package com.pur.zsms.supplier.web;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.cglib.beans.BeanCopier;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.pur.zsms.accountmanage.vo.AccountVo;
import com.pur.zsms.check.vo.CheckVo;
import com.pur.zsms.common.exception.GenericException;
import com.pur.zsms.common.support.PageController;
import com.pur.zsms.common.support.PaginationSupport;
import com.pur.zsms.common.util.ExcelReader;
import com.pur.zsms.common.util.FileUtill;
import com.pur.zsms.common.util.PubFun;
import com.pur.zsms.documentsmanage.vo.DomVo;
import com.pur.zsms.lockmanage.service.ILockTransService;
import com.pur.zsms.matermanage.mater.vo.MaterVo;
import com.pur.zsms.matermanage.mater.vo.MaterVoForCostSupplier;
import com.pur.zsms.ordercustommanage.po.OrderSupplierMaterPo;
import com.pur.zsms.ordercustommanage.po.OrderSupplierPo;
import com.pur.zsms.ordercustommanage.vo.ExcelVo;
import com.pur.zsms.ordercustommanage.vo.OrderCustVo;
import com.pur.zsms.pmsnmanage.menu.po.MenuPo;
import com.pur.zsms.pmsnmanage.role.service.IRoleService;
import com.pur.zsms.pmsnmanage.role.vo.RoleVo;
import com.pur.zsms.pmsnmanage.user.po.UserPo;
import com.pur.zsms.pmsnmanage.user.po.UserRolePo;
import com.pur.zsms.pmsnmanage.user.service.IUserService;
import com.pur.zsms.pmsnmanage.user.vo.UserVo;
import com.pur.zsms.pmsnmanage.user.web.UserControllor;
import com.pur.zsms.po.SupplierShopPo;
import com.pur.zsms.storemanage.po.StoreOutPo;
import com.pur.zsms.storemanage.service.IStoreService;
import com.pur.zsms.storemanage.vo.StoreOutVo;
import com.pur.zsms.supplier.po.ShopSupplierTypePo;
import com.pur.zsms.supplier.po.SupplierPo;
import com.pur.zsms.supplier.service.ISupplierOrderService;
import com.pur.zsms.supplier.service.ISupplierService;
import com.pur.zsms.supplier.vo.ShopSupplierTypeVo;
import com.pur.zsms.supplier.vo.ShopSupplierVo;
import com.pur.zsms.supplier.vo.SupplierDistributeVo;
import com.pur.zsms.supplier.vo.SupplierOrderCustVo;
import com.pur.zsms.supplier.vo.SupplierQualificationVo;
import com.pur.zsms.supplier.vo.SupplierVo;
import com.pur.zsms.systemsetting.datadictionary.po.Code;
import com.pur.zsms.systemsetting.datadictionary.vo.CodeVo;
import com.pur.zsms.timecontrol.service.ITimeControlService;
import com.pur.zsms.vo.SupplierShopVo;

/**
 * 供应商控制器
 * 
 * @author yuxin
 * 
 */
@Controller
@RequestMapping(value = "/supplier")
public class SupplierController {
	@SuppressWarnings("unused")
	private static final Logger log = LoggerFactory.getLogger(SupplierController.class);
	protected int page = 1;

	protected int pageSize = 15;

	PaginationSupport pageList;

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	@Resource(name = "supplierOrderService")
	private ISupplierOrderService supplierOrderService;

	@Resource(name = "supplierService")
	private ISupplierService supplierService;

	@Resource(name = "timeControlService")
	private ITimeControlService timeControlService;

	@Resource(name = "userService")
	private IUserService userService;

	@Resource(name = "lockTransService")
	private ILockTransService lockTransService;

	@Resource(name = "storeService")
	private IStoreService storeService;

	@Resource(name = "roleService")
	private IRoleService roleService;

	@RequestMapping(value = "/findsupplier.do")
	@ResponseBody
	public String findsupplier(@RequestParam(required = false) String page, @RequestParam(required = false) String rows, SupplierVo suppVo)
			throws GenericException, IllegalAccessException, InvocationTargetException {
		JSONObject json = new JSONObject();
		log.info("----");
		if (page == null || page.equals(""))
			page = "1";
		if (rows == null || rows.equals(""))
			rows = "10";
		PageController pageController = new PageController(Integer.parseInt(page), Integer.parseInt(rows));
		this.pageList = supplierService.listSupplier(pageController, suppVo);
		List<SupplierVo> list = new ArrayList<SupplierVo>();
		List items = pageList.getItems();
		if (items != null) {
			for (int i = 0; i < items.size(); i++) {
				Object[] item = (Object[]) items.get(i);
				SupplierVo v = new SupplierVo();
				v.setSupplierId((Integer) item[0]);
				v.setCompanyName((String) item[1]);
				if (item[10] != null) {
					v.setProvince(Integer.valueOf(item[10].toString()));
				}
				if (item[11] != null) {
					v.setCity(Integer.valueOf(item[11].toString()));
				}
				v.setStreet((String) item[13]);
				v.setPhone((String) item[4]);
				if (item[8] != null) {
					v.setMobile(item[8].toString());
				}
				v.setIsActive((String) item[16]);
				if (item[17] != null) {
					v.setInsertTime(item[17].toString());
				}
				v.setUserId(Long.valueOf(item[19].toString()));
				v.setUserName((String) item[20]);
				list.add(v);
			}

			json.put("success", true);
			json.put("total", pageList.getTotalCount());
			json.put("rows", list);
			log.info("----" + json.toString());
		} else {
			json.put("success", false);
			json.put("total", pageList.getTotalCount());
			json.put("rows", "");
			log.info("----" + json.toString());
		}

		return json.toString();
	}

	@RequestMapping(value = "/deleteSupplier.do", method = { RequestMethod.POST })
	@ResponseBody
	public String deleteRole(int supplierId) {
		JSONObject json = new JSONObject();
		try {
			supplierService.deleteUser(supplierId);
			json.put("success", true);
		} catch (Exception e) {
			json.put("success", false);
		}
		return json.toString();
	}

	@RequestMapping(value = "/findsupCus.do")
	@ResponseBody
	public String findsupCus(@RequestParam(required = false) String page, @RequestParam(required = false) String rows, ShopSupplierVo suppVo,
			HttpSession session) throws GenericException {
		JSONObject json = new JSONObject();
		log.info("----");
		if (page == null || page.equals(""))
			page = "1";
		if (rows == null || rows.equals(""))
			rows = "10";
		PageController pageController = new PageController(Integer.parseInt(page), Integer.parseInt(rows));
		this.pageList = supplierService.listSupCus(pageController, suppVo);
		List<ShopSupplierVo> list = new ArrayList<ShopSupplierVo>();
		List items = pageList.getItems();
		if (items != null) {
			for (int i = 0; i < items.size(); i++) {
				Object[] item = (Object[]) items.get(i);
				ShopSupplierVo f = new ShopSupplierVo();
				f.setShopSpplierId((Integer) item[0]);
				f.setShopId((Integer) item[1]);
				f.setSupId((Integer) item[2]);
				f.setSupTypeAll((String) item[3]);
				f.setShopName((String) item[4]);
				f.setSupName((String) item[5]);

				list.add(f);
			}

			json.put("success", true);
			json.put("total", pageList.getTotalCount());
			json.put("rows", list);
			log.info("----" + json.toString());
		} else {
			json.put("success", false);
			json.put("total", pageList.getTotalCount());
			json.put("rows", "");
			log.info("----" + json.toString());
		}

		return json.toString();
	}

	@RequestMapping(value = "/preSaveSupper.do", method = { RequestMethod.GET })
	public ModelAndView preSaveSupper(int companyId) {

		List<RoleVo> roleList = null;
		List<Code> typeList = null;
		try {
			// 先根据companyId查询角色标记

			// roleService.findRole(companyId);
			//roleService.findRoleByCompanyIdForSupplier(companyId);

			roleList = userService.listRoleByIdentity(""); // 查询所有角色信息
			typeList = supplierService.listAllSuptype(); // 查询所有菜单信息

		} catch (GenericException e) {
			e.printStackTrace();
		}
		Map map = new HashMap();
		map.put("rolelist", roleList);
		map.put("typeList", typeList);
		map.put("companyId", companyId);

		return new ModelAndView("/supplier/addSupper", map);
	}

	@RequestMapping(value = "/preSaveSupperForSup.do", method = { RequestMethod.GET })
	public ModelAndView preSaveSupperForSup() {

		List<RoleVo> roleList = null;
		List<Code> typeList = null;
		try {
			roleList = userService.listAllRole(); // 查询所有角色信息
			typeList = supplierService.listAllSuptype(); // 查询所有菜单信息
		} catch (GenericException e) {
			e.printStackTrace();
		}
		Map map = new HashMap();
		map.put("rolelist", roleList);
		map.put("typeList", typeList);

		return new ModelAndView("/supplier/addSupperForSup", map);
	}

	@RequestMapping(value = "/saveSupplier.do", method = { RequestMethod.POST })
	@ResponseBody
	public String saveSupplier(SupplierVo c, HttpSession session) {
		JSONObject json = new JSONObject();
		UserPo lgUser = (UserPo) session.getAttribute("user");
		try {
			/*
			 * UserPo userInfo = (UserPo) session.getAttribute("user"); int
			 * supId = supplierService.getSupIdByUserId(userInfo.getUserId());
			 * c.setSupId(supId);
			 */
			c.setCompanyName(c.getRealName());
			c.setPhone(String.valueOf(c.getUserPhone()));
			if (c.getUserFlag() == 3) {
				long userId = userService.addUserForSupplier(c, lgUser);
				c.setUserId(userId);
			}
			boolean flag = supplierService.addSupplier(c);
			if (flag) {
				json.put("success", true);
			} else {
				json.put("success", false);
				json.put("msg", supplierService.getMsg());
			}
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
		}
		return json.toString();
	}

	@RequestMapping(value = "/preSaveSupperCus.do", method = { RequestMethod.GET })
	public ModelAndView preSaveSupperCus() {
		List<Code> typeList = null;
		try {
			typeList = supplierService.listAllSuptype(); // 查询所有菜单信息
		} catch (GenericException e) {
			e.printStackTrace();
		}
		Map map = new HashMap();
		map.put("typeList", typeList);
		return new ModelAndView("/supplier/addSupperCust", map);
	}

	@RequestMapping(value = "/saveSupplierCust.do", method = { RequestMethod.POST })
	@ResponseBody
	public String saveSupplierCust(ShopSupplierVo c, Long[] suptypes, HttpSession session) {
		JSONObject json = new JSONObject();
		try {

			boolean flag = supplierService.addSupplierCust(c, suptypes);
			if (flag) {
				json.put("success", true);
			} else {
				json.put("success", false);
				json.put("msg", supplierService.getMsg());
			}
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
		}
		return json.toString();
	}

	@RequestMapping(value = "/preUpdateSupperCus.do", method = { RequestMethod.GET })
	public ModelAndView preUpdateSupperCus(int shopId, int supId) {
		List<CodeVo> typeList = null;
		ShopSupplierVo shopSupplierVo = new ShopSupplierVo();
		try {
			shopSupplierVo.setSupId(supId);
			shopSupplierVo.setShopId(shopId);
			typeList = supplierService.listAllSuptypeByUpdate(shopId, supId); // 查询所有菜单信息
		} catch (GenericException e) {
			e.printStackTrace();
		}
		Map map = new HashMap();
		map.put("shopSupplierVo", shopSupplierVo);

		map.put("typeList", typeList);
		return new ModelAndView("/supplier/updateSupperCust", map);
	}

	@RequestMapping(value = "/updateShopSupplier.do", method = { RequestMethod.POST })
	@ResponseBody
	public String updateShopSupplier(ShopSupplierVo c, Long[] suptypes) {
		JSONObject json = new JSONObject();
		try {

			boolean flag = supplierService.updateShopSupplier(c, suptypes);
			if (flag) {
				json.put("success", true);
			} else {
				json.put("success", false);
				json.put("msg", supplierService.getMsg());
			}
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
		}
		return json.toString();
	}

	@RequestMapping(value = "/deleteShopSupplier.do", method = { RequestMethod.POST })
	@ResponseBody
	public String deleteShopSupplier(int shopId, int supId) {
		JSONObject json = new JSONObject();
		try {
			supplierService.deleteShopSupplier(shopId, supId);
			json.put("success", true);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
			json.put("msg", e.getMessage());
		}
		return json.toString();
	}

	@RequestMapping(value = "/preUpdateSupplier.do", method = { RequestMethod.GET })
	public ModelAndView preUpdateSupplier(String supplierId, String userId) {
		JSONObject json = new JSONObject();
		SupplierVo supplierVo = new SupplierVo();
		UserVo user = new UserVo();
		List<RoleVo> list = null;
		try {
			supplierVo = supplierService.getSupVoBySupId(supplierId); // 查询所有角色信息
			user = userService.listUserByUserId(userId);

			supplierVo.setRealName(user.getRealName());
			supplierVo.setUserName(user.getUserName());
			supplierVo.setPhone(String.valueOf(user.getUserPhone()));
			supplierVo.setUserPhone(user.getUserPhone());

			supplierVo.setEmail(user.getEmail());
			supplierVo.setOrganId(user.getOrganId());
			list = userService.listRoleByUserId(userId);

		} catch (GenericException e) {
			e.printStackTrace();
		}
		Map map = new HashMap();
		map.put("supplierVo", supplierVo);
		map.put("rolelist", list);

		return new ModelAndView("/supplier/updateSupper", map);
	}

	@RequestMapping(value = "/updateSupplier.do", method = { RequestMethod.POST })
	@ResponseBody
	public String updateSupplier(SupplierVo c) {
		JSONObject json = new JSONObject();
		try {
			userService.updateUserForSupplier(c);
			c.setCompanyName(c.getRealName());
			c.setPhone(String.valueOf(c.getUserPhone()));
			String rmsg = supplierService.updateSupplier(c);
			if (!rmsg.equals("0000")) {
				json.put("success", false);
				json.put("msg", rmsg);
				return json.toString();
			}
			json.put("success", true);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
		}
		return json.toString();
	}

	// 进货报表导出
	@RequestMapping(value = "/exportSupperExcelCost.do", method = { RequestMethod.POST })
	@ResponseBody
	public String exportSupperExcelCost(HttpServletRequest request, HttpServletResponse response, HttpSession session1, String orderDate, int supId)
			throws Exception {
		JSONObject json = new JSONObject();
		HttpSession session = request.getSession();
		session.setAttribute("state", null);
		// 生成提示信息，
		String codedFileName = null;
		String codedFileNameUser = null;

		OutputStream fOut = null;
		UserPo userInfo = (UserPo) session1.getAttribute("user");

		try {

			response.setContentType("application/vnd.ms-excel");

			// 根据用户id得出supid
			if (supId == 0) {
				supId = supplierService.getSupIdByUserId(userInfo.getUserId());
			}

			boolean lockFlag = lockTransService.lockTrans("exportSupperExcelCost.do", supId);
			if (!lockFlag) {
				json.put("msg", "locked");
				json.put("success", false);
				return json.toString();
			}
			// 进行转码，使其支持中文文件名
			// codedFileName = java.net.URLEncoder.encode("Quotation" + supId +
			// "_" + orderDate, "UTF-8");
			// codedFileName = new String("报价单".getBytes("GBK"), "ISO8859-1");
			// response.setHeader("content-disposition", "attachment;filename="
			// + codedFileName + "_" + orderDate + ".xls");
			// response.addHeader("Content-Disposition",
			// "attachment;   filename=" + codedFileName + ".xls");
			// 产生工作簿对象
			HSSFWorkbook workbook = new HSSFWorkbook();
			// 产生工作表对象

			HSSFSheet sheet = workbook.createSheet();

			// 设定自动适应列宽
			for (int i = 0; i < 20; i++) {
				sheet.autoSizeColumn(i);
			}
			// 边框
			HSSFCellStyle setBorder = workbook.createCellStyle();
			setBorder.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
			setBorder.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
			setBorder.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
			setBorder.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
			setBorder.setAlignment(HSSFCellStyle.VERTICAL_CENTER);

			HSSFFont font = workbook.createFont();
			font.setFontName("宋体");
			font.setFontHeightInPoints((short) 22);
			HSSFCellStyle cellStyle = workbook.createCellStyle();
			cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
			cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
			cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
			cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
			cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
			cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平居中
			cellStyle.setFont(font);

			// sheet.setColumnHidden(0, true);// 隐藏列
			sheet.setColumnHidden(1, true);// 隐藏列
			sheet.setColumnHidden(2, true);// 隐藏列
			sheet.setColumnHidden(3, true);// 隐藏列
			sheet.setColumnHidden(4, true);// 隐藏列

			int sheetIndex = 0;
			// 初始行设置
			HSSFRow rowfist = sheet.createRow((int) 0);// 创建一行
			rowfist.setHeight((short) 340);// 行高

			int totalLine = 0;

			HSSFCell cellFirst1 = rowfist.createCell(totalLine);// 创建一列
			cellFirst1.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst1.setCellValue("材料Id");
			cellFirst1.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst3 = rowfist.createCell(totalLine);// 创建一列
			cellFirst3.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst3.setCellValue("材料品级");
			cellFirst3.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst4 = rowfist.createCell(totalLine);// 创建一列
			cellFirst4.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst4.setCellValue("供货商ID");
			cellFirst4.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst5 = rowfist.createCell(totalLine);// 创建一列
			cellFirst5.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst5.setCellValue("供货商名");
			cellFirst5.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst7 = rowfist.createCell(totalLine);// 创建一列
			cellFirst7.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst7.setCellValue("时间");
			cellFirst7.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst8 = rowfist.createCell(totalLine);// 创建一列
			cellFirst8.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst8.setCellValue("单位价格");
			cellFirst8.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst9 = rowfist.createCell(totalLine);// 创建一列
			cellFirst9.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst9.setCellValue("总价格");
			cellFirst9.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst10 = rowfist.createCell(totalLine);// 创建一列
			cellFirst10.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst10.setCellValue("种类");
			cellFirst10.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst12 = rowfist.createCell(totalLine);// 创建一列
			cellFirst12.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst12.setCellValue("品牌");
			cellFirst12.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst13 = rowfist.createCell(totalLine);// 创建一列
			cellFirst13.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst13.setCellValue("规格");
			cellFirst13.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst2 = rowfist.createCell(totalLine);// 创建一列
			cellFirst2.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst2.setCellValue("材料名");
			cellFirst2.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst11 = rowfist.createCell(totalLine);// 创建一列
			cellFirst11.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst11.setCellValue("单位");
			cellFirst11.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst6 = rowfist.createCell(totalLine);// 创建一列
			cellFirst6.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst6.setCellValue("总重量");
			cellFirst6.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			// // 总表的分表标题
			List<Object[]> listCust = supplierService.getExcelCust(orderDate, supId);
			//
			// if (listCust != null && listCust.size() > 0) {
			// /*
			// * for (int i = 0; i < listCust.size(); i++) {
			// * sheet.setColumnWidth(totalLine, 3000); HSSFCell cellFirstfen
			// * = rowfist.createCell(totalLine); totalLine = totalLine + 1;
			// * cellFirstfen.setCellType(HSSFCell.CELL_TYPE_STRING);
			// * cellFirstfen.setCellValue(listCust.get(i)[1].toString());//
			// * 分店名称 cellFirstfen.setCellStyle(setBorder); }
			// */
			// }
			//
			// // 根据日期取得 总表数据
			// List<Object[]> listTotal =
			// supplierService.getAllTotalByDate(orderDate, supId);
			//
			// for (int i = 0; i < listTotal.size(); i++) {
			//
			// Object[] a = listTotal.get(i);
			// HSSFRow row = sheet.createRow((int) i + 1);// 创建一行
			// row.setHeight((short) 340);// 行高
			//
			// int totalDateLine = 0;
			//
			// HSSFCell cell1 = row.createCell(totalDateLine);// 创建一列 材料Id
			// cell1.setCellType(HSSFCell.CELL_TYPE_STRING);
			// cell1.setCellValue(a[0].toString());
			// cell1.setCellStyle(setBorder);
			// totalDateLine = totalDateLine + 1;
			//
			// HSSFCell cell3 = row.createCell(totalDateLine);// 创建一列 材料品级
			// cell3.setCellType(HSSFCell.CELL_TYPE_STRING);
			// cell3.setCellValue(a[1].toString());
			// cell3.setCellStyle(setBorder);
			// totalDateLine = totalDateLine + 1;
			//
			// HSSFCell cell4 = row.createCell(totalDateLine);// 创建一列 供货商ID
			// cell4.setCellType(HSSFCell.CELL_TYPE_STRING);
			// cell4.setCellValue(a[2].toString());
			// cell4.setCellStyle(setBorder);
			// totalDateLine = totalDateLine + 1;
			//
			// HSSFCell cell5 = row.createCell(totalDateLine);// 创建一列 供货商name
			// cell5.setCellType(HSSFCell.CELL_TYPE_STRING);
			// cell5.setCellValue(a[5].toString());
			// cell5.setCellStyle(setBorder);
			// totalDateLine = totalDateLine + 1;
			//
			// HSSFCell cell7 = row.createCell(totalDateLine);// 创建一列 时间
			// cell7.setCellType(HSSFCell.CELL_TYPE_STRING);
			// cell7.setCellValue(orderDate);
			// cell7.setCellStyle(setBorder);
			// totalDateLine = totalDateLine + 1;
			//
			// HSSFCell cell8 = row.createCell(totalDateLine);// 创建一列 每公斤价格
			// cell8.setCellType(HSSFCell.CELL_TYPE_STRING);
			// cell8.setCellStyle(setBorder);
			// if (a[10] == null) {
			// cell8.setCellValue("");
			// } else {
			// BigDecimal materValue = new
			// BigDecimal(a[10].toString()).multiply(new
			// BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_UP);
			// cell8.setCellValue(materValue.toString());
			// }
			//
			// totalDateLine = totalDateLine + 1;
			//
			// HSSFCell cell9 = row.createCell(totalDateLine);// 创建一列 总价格
			// cell9.setCellType(HSSFCell.CELL_TYPE_STRING);
			// cell9.setCellStyle(setBorder);
			// cell9.setCellFormula("F" + (i + 2) + "*M" + (i + 2));
			//
			// totalDateLine = totalDateLine + 1;
			//
			// HSSFCell cell10 = row.createCell(totalDateLine);// 创建一列 种类
			// cell10.setCellType(HSSFCell.CELL_TYPE_STRING);
			// cell10.setCellValue(a[6].toString());
			// cell10.setCellStyle(setBorder);
			// totalDateLine = totalDateLine + 1;
			//
			// HSSFCell cell12 = row.createCell(totalDateLine);// 创建一列 品牌
			// cell12.setCellType(HSSFCell.CELL_TYPE_STRING);
			// cell12.setCellValue(a[8].toString());
			// cell12.setCellStyle(setBorder);
			// totalDateLine = totalDateLine + 1;
			//
			// HSSFCell cell13 = row.createCell(totalDateLine);// 创建一列 规格
			// cell13.setCellType(HSSFCell.CELL_TYPE_STRING);
			// cell13.setCellValue(a[9].toString());
			// cell13.setCellStyle(setBorder);
			// totalDateLine = totalDateLine + 1;
			//
			// HSSFCell cell2 = row.createCell(totalDateLine);// 创建一列 材料名
			// cell2.setCellType(HSSFCell.CELL_TYPE_STRING);
			// cell2.setCellValue(a[4].toString());
			// cell2.setCellStyle(setBorder);
			// totalDateLine = totalDateLine + 1;
			//
			// HSSFCell cell11 = row.createCell(totalDateLine);// 创建一列 单位
			// cell11.setCellType(HSSFCell.CELL_TYPE_STRING);
			// cell11.setCellValue(a[7].toString());
			// cell11.setCellStyle(setBorder);
			// totalDateLine = totalDateLine + 1;
			//
			// HSSFCell cell6 = row.createCell(totalDateLine);// 创建一列
			// cell6.setCellType(HSSFCell.CELL_TYPE_STRING);
			// cell6.setCellValue(a[3].toString());
			// cell6.setCellStyle(setBorder);
			// totalDateLine = totalDateLine + 1;
			//
			// /*
			// * if (listCust != null && listCust.size() > 0) { for (int j =
			// * 0; j < listCust.size(); j++) { String custId =
			// * listCust.get(j)[0].toString(); String custName =
			// * listCust.get(j)[1].toString();
			// *
			// * List<Object[]> listCustTotalDate = supplierService
			// * .getExcelCustTotalRealMaterByDateMaterIdMaterLevel(orderDate,
			// * supId, custId, a[0].toString(), a[1].toString()); if
			// * (listCustTotalDate != null && listCustTotalDate.size() > 0) {
			// * HSSFCell cellCustTotalDate = row.createCell(totalDateLine);
			// * // 创建一列
			// * cellCustTotalDate.setCellType(HSSFCell.CELL_TYPE_STRING);
			// * Object ad = (Object) listCustTotalDate.get(0);
			// * cellCustTotalDate.setCellValue(ad.toString());
			// * cellCustTotalDate.setCellStyle(setBorder); totalDateLine =
			// * totalDateLine + 1; } else { HSSFCell cellCustTotalDate =
			// * row.createCell(totalDateLine); // 创建一列
			// * cellCustTotalDate.setCellType(HSSFCell.CELL_TYPE_STRING);
			// * cellCustTotalDate.setCellValue("0");
			// * cellCustTotalDate.setCellStyle(setBorder); totalDateLine =
			// * totalDateLine + 1; } } }
			// */
			//
			// }

			workbook.setSheetName(sheetIndex, "总表");

			// 总表 分店显示材料数量

			// 生成店长需求sheet
			if (listCust != null && listCust.size() > 0) {
				for (int i = 0; i < listCust.size(); i++) {

					String custId = listCust.get(i)[0].toString();
					String custName = listCust.get(i)[1].toString();

					List<Object[]> listCustDate = supplierService.getExcelCustAllRealMaterByDate(orderDate, supId, custId);

					if (listCustDate != null && listCustDate.size() > 0) {
						// 初始行设置
						HSSFSheet sheetCust = workbook.createSheet();

						sheetCust.setColumnWidth(1, 5000);
						sheetCust.setColumnWidth(4, 5000);
						sheetCust.setColumnWidth(7, 4000);
						sheetCust.setColumnWidth(9, 4000);

						sheetCust.setColumnHidden(0, true);// 隐藏列
						sheetCust.setColumnHidden(2, true);// 隐藏列
						sheetCust.setColumnHidden(6, true);// 隐藏列

						sheetCust.setMargin(HSSFSheet.TopMargin, (double) 0.3);// 页边距（上）
						sheetCust.setMargin(HSSFSheet.BottomMargin, (double) 0.3);// 页边距（下）
						sheetCust.setMargin(HSSFSheet.LeftMargin, (double) 0.3);// 页边距（左）
						sheetCust.setMargin(HSSFSheet.RightMargin, (double) 0.3);// 页边距（右
						sheetCust.setHorizontallyCenter(true);// 打印水平居中

						HSSFRow row = sheetCust.createRow(0);// 创建一行
						row.setHeight((short) 500);// 行高
						HSSFCell cell = row.createCell(0);// 创建一列

						// 取得摊位号
						SupplierShopVo tSupplierShopVo = new SupplierShopVo();
						tSupplierShopVo.setSupId(supId);
						tSupplierShopVo.setShopId(Integer.valueOf(custId));
						List<SupplierShopPo> supplierShopPoList = supplierService.getSupplierShopPo(tSupplierShopVo);

						sheetCust.addMergedRegion(new CellRangeAddress(0, 0, 0, 9));
						cell.setCellType(HSSFCell.CELL_TYPE_STRING);
						if (supplierShopPoList != null && supplierShopPoList.size() > 0 && supplierShopPoList.get(0).getCode() != null
								&& !"".equals(supplierShopPoList.get(0).getCode())) {
							cell.setCellValue("（摊位号：" + supplierShopPoList.get(0).getCode() + "）"
									+ supplierService.getSupNameByUserId(userInfo.getUserId()) + PubFun.getCurrentDate() + "对货单");
						} else {
							cell.setCellValue(supplierService.getSupNameByUserId(userInfo.getUserId()) + PubFun.getCurrentDate() + "对货单");
						}
						cell.setCellStyle(cellStyle);

						int custTitleLine = 0;
						HSSFRow rowCustfist = sheetCust.createRow(1);// 创建一行
						rowCustfist.setHeight((short) 340);// 行高

						HSSFCell cellCustFirst1 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst1.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst1.setCellValue("店id");
						cellCustFirst1.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst2 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst2.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst2.setCellValue("店名");
						cellCustFirst2.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst3 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst3.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst3.setCellValue("材料Id");
						cellCustFirst3.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst9 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst9.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst9.setCellValue("种类");
						cellCustFirst9.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst4 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst4.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst4.setCellValue("材料名");
						cellCustFirst4.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst6 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst6.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst6.setCellValue("单位");
						cellCustFirst6.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst5 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst5.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst5.setCellValue("材料品级");
						cellCustFirst5.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst10 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst10.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst10.setCellValue("规格");
						cellCustFirst10.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst7 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst7.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst7.setCellValue("需求重量");
						cellCustFirst7.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst8 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst8.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst8.setCellValue("留言");
						cellCustFirst8.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						for (int j = 0; j < listCustDate.size(); j++) {

							HSSFRow rowCustDate = sheetCust.createRow((int) j + 2);// 创建一行
							rowCustDate.setHeight((short) 340);// 行高

							int custDateLine = 0;
							HSSFCell cellCustDate1 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate1.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate1.setCellValue(custId);
							cellCustDate1.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate2 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate2.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate2.setCellValue(custName);
							cellCustDate2.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate3 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate3.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate3.setCellValue(listCustDate.get(j)[0].toString());
							cellCustDate3.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate12 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate12.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate12.setCellValue(listCustDate.get(j)[8].toString());
							cellCustDate12.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate4 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate4.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate4.setCellValue(listCustDate.get(j)[4].toString());
							cellCustDate4.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate9 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate9.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate9.setCellValue(listCustDate.get(j)[5].toString());
							cellCustDate9.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate5 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate5.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate5.setCellValue(listCustDate.get(j)[1].toString());
							cellCustDate5.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate10 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate10.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate10.setCellValue(listCustDate.get(j)[6].toString());
							cellCustDate10.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate7 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate7.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate7.setCellValue(listCustDate.get(j)[3].toString());
							cellCustDate7.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate8 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate8.setCellType(HSSFCell.CELL_TYPE_STRING);
							if (listCustDate.get(j)[7] != null && !listCustDate.get(j)[7].equals("")) {
								cellCustDate8.setCellValue("@" + listCustDate.get(j)[7].toString() + "@");
							}
							cellCustDate8.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

						}
						workbook.setSheetName(sheetIndex + 1, custName + "(" + (sheetIndex + 1) + ")");
						sheetIndex = sheetIndex + 1;
					}
					// ----------------------
					/*
					 * HSSFSheet sheetCust = workbook.createSheet(); HSSFRow
					 * rowCust = sheetCust.createRow((int) i + 1);// 创建一行
					 * 
					 * HSSFCell cellCust1 = rowCust.createCell((int) 0);// 创建一列
					 * cellCust1.setCellType(HSSFCell.CELL_TYPE_STRING);
					 * cellCust1.setCellValue(listCust.get(i)[0].toString());
					 * cellCust1.setCellStyle(setBorder);
					 */
				}

			}
			workbook.removeSheetAt(workbook.getSheetIndex("总表"));
			sheet.setForceFormulaRecalculation(true);

			InputStream excelStream = null;

			ByteArrayOutputStream out = new ByteArrayOutputStream();

			HSSFWorkbook hssWb = (HSSFWorkbook) workbook;

			hssWb.write(out);

			excelStream = new ByteArrayInputStream(out.toByteArray());

			out.close();

			String realPath = session1.getServletContext().getRealPath("/");

			String filePath = realPath + File.separator + "jsp" + File.separator + "templet" + File.separator + "excelSupperLookPrint";

			FileUtill.saveFileFromInputStream(excelStream, filePath, supId + "_" + "报价单" + "_" + orderDate + ".xls");
		} catch (Exception e) {
		} finally {
			lockTransService.unlockTrans("exportSupperExcelCost.do", supId);

		}

		json.put("success", true);
		return json.toString();
	}

	/**
	 * 下载分货表
	 */
	@RequestMapping(value = "/exportSupperExcelCostDown.do", method = { RequestMethod.POST })
	@ResponseBody
	public String exportSupperExcelCostDown(HttpServletRequest request, HttpServletResponse response, HttpSession session1, String orderDate,
			int supId) throws Exception {
		JSONObject json = new JSONObject();

		UserPo userInfo = (UserPo) session1.getAttribute("user");
		// 根据用户id得出supid
		if (supId == 0) {
			supId = supplierService.getSupIdByUserId(userInfo.getUserId());
		}

		boolean lockFlag = lockTransService.lockTrans("exportSupperExcelCost.do", supId);
		if (!lockFlag) {
			json.put("msg", "locked");
			json.put("success", false);
			return json.toString();
		}
		OutputStream toClient = null;
		try {

			String filename = supId + "_" + "报价单" + "_" + orderDate + ".xls";
			// 以流的形式下载文件。
			String realPath = session1.getServletContext().getRealPath("/");
			String filePath = realPath + File.separator + "jsp" + File.separator + "templet" + File.separator + "excelSupperLookPrint"
					+ File.separator;
			InputStream fis = new BufferedInputStream(new FileInputStream(filePath + filename));
			byte[] buffer = new byte[fis.available()];
			fis.read(buffer);

			// 清空response
			response.reset();
			// 设置response的Header
			// response.addHeader("Content-Disposition", "attachment;filename="
			// + new String(filename.getBytes()));

			response.setContentType("octets/stream");
			response.addHeader("Content-Type", "text/html; charset=utf-8");
			String downLoadName = new String(filename.getBytes("gbk"), "iso8859-1");
			response.addHeader("Content-Disposition", "attachment;filename=" + downLoadName);

			toClient = new BufferedOutputStream(response.getOutputStream());
			toClient.write(buffer);
			fis.close();
		} catch (Exception e) {
		} finally {
			lockTransService.unlockTrans("exportSupperExcelCost.do", supId);
			try {
				toClient.flush();
				toClient.close();
			} catch (IOException e) {
			}
		}
		json.put("msg", "msg001");
		json.put("success", false);
		return json.toString();
	}

	// 送货报表导出(实际价格)
	@RequestMapping(value = "/exportSupperExcel.do", method = { RequestMethod.POST })
	@ResponseBody
	public String exportSupperExcel(HttpServletRequest request, HttpServletResponse response, HttpSession session1, String orderDate, int supId,
			int custIdDeal, String custIdAll, int valueType, String orderBy) {
		JSONObject json = new JSONObject();
		HttpSession session = request.getSession();
		session.setAttribute("state", null);
		// 生成提示信息，
		String codedFileName = null;
		String codedFileNameUser = null;

		OutputStream fOut = null;
		UserPo userInfo = (UserPo) session1.getAttribute("user");

		/*
		 * // 增加对时间的校验 boolean flagTime = false; try { flagTime =
		 * timeControlService.timeControl(userInfo.getUserId(), orderDate); }
		 * catch (Exception e2) { e2.printStackTrace(); } if (!flagTime && supId
		 * == 0) { json.put("msg", "msg001");
		 * 
		 * json.put("success", false); return json.toString(); }
		 */

		try {

			response.setContentType("application/vnd.ms-excel");

			// 根据用户id得出supid

			if (supId == 0) {
				supId = supplierService.getSupIdByUserId(userInfo.getUserId());
			}
			// 进行转码，使其支持中文文件名
			// codedFileName = java.net.URLEncoder.encode("Quotation" + supId +
			// "_" + orderDate, "UTF-8");
			codedFileName = new String("报价单".getBytes("GBK"), "ISO8859-1");
			response.setHeader("content-disposition", "attachment;filename=" + codedFileName + "_" + orderDate + ".xls");
			// response.addHeader("Content-Disposition",
			// "attachment;   filename=" + codedFileName + ".xls");
			// 产生工作簿对象
			HSSFWorkbook workbook = new HSSFWorkbook();
			// 产生工作表对象

			HSSFSheet sheet = workbook.createSheet();

			// 设定自动适应列宽
			for (int i = 0; i < 20; i++) {
				sheet.autoSizeColumn(i);
			}
			// 边框
			HSSFCellStyle setBorder = workbook.createCellStyle();
			setBorder.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
			setBorder.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
			setBorder.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
			setBorder.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
			setBorder.setAlignment(HSSFCellStyle.VERTICAL_CENTER);
			sheet.setColumnHidden(0, true);// 隐藏列
			sheet.setColumnHidden(1, true);// 隐藏列
			sheet.setColumnHidden(2, true);// 隐藏列
			sheet.setColumnHidden(3, true);// 隐藏列
			sheet.setColumnHidden(4, true);// 隐藏列

			int sheetIndex = 0;
			// 初始行设置
			HSSFRow rowfist = sheet.createRow((int) 0);// 创建一行
			rowfist.setHeight((short) 340);// 行高

			int totalLine = 0;

			HSSFCell cellFirst1 = rowfist.createCell(totalLine);// 创建一列
			cellFirst1.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst1.setCellValue("材料Id");
			cellFirst1.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst3 = rowfist.createCell(totalLine);// 创建一列
			cellFirst3.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst3.setCellValue("材料品级");
			cellFirst3.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst4 = rowfist.createCell(totalLine);// 创建一列
			cellFirst4.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst4.setCellValue("供货商ID");
			cellFirst4.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst5 = rowfist.createCell(totalLine);// 创建一列
			cellFirst5.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst5.setCellValue("供货商名");
			cellFirst5.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst7 = rowfist.createCell(totalLine);// 创建一列
			cellFirst7.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst7.setCellValue("时间");
			cellFirst7.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst8 = rowfist.createCell(totalLine);// 创建一列
			cellFirst8.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst8.setCellValue("单位价格");
			cellFirst8.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst9 = rowfist.createCell(totalLine);// 创建一列
			cellFirst9.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst9.setCellValue("总价格");
			cellFirst9.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst10 = rowfist.createCell(totalLine);// 创建一列
			cellFirst10.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst10.setCellValue("种类");
			cellFirst10.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst12 = rowfist.createCell(totalLine);// 创建一列
			cellFirst12.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst12.setCellValue("品牌");
			cellFirst12.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst13 = rowfist.createCell(totalLine);// 创建一列
			cellFirst13.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst13.setCellValue("规格");
			cellFirst13.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst2 = rowfist.createCell(totalLine);// 创建一列
			cellFirst2.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst2.setCellValue("材料名");
			cellFirst2.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst11 = rowfist.createCell(totalLine);// 创建一列
			cellFirst11.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst11.setCellValue("单位");
			cellFirst11.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			HSSFCell cellFirst6 = rowfist.createCell(totalLine);// 创建一列
			cellFirst6.setCellType(HSSFCell.CELL_TYPE_STRING);
			cellFirst6.setCellValue("总重量");
			cellFirst6.setCellStyle(setBorder);
			totalLine = totalLine + 1;

			// 总表的分表标题
			List<Object[]> listCust = supplierService.getExcelCust(orderDate, supId, custIdAll);
			/*
			 * if (listCust != null && listCust.size() > 0) { for (int i = 0; i
			 * < listCust.size(); i++) { sheet.setColumnWidth(totalLine, 3000);
			 * 
			 * HSSFCell cellFirstfen = rowfist.createCell(totalLine); totalLine
			 * = totalLine + 1;
			 * cellFirstfen.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cellFirstfen.setCellValue(listCust.get(i)[1].toString());// 分店名称
			 * cellFirstfen.setCellStyle(setBorder); } }
			 */

			/*
			 * // 根据日期取得 总表数据 List<Object[]> listTotal = null; if (custIdDeal !=
			 * 0) { listTotal = supplierService.getAllTotalByDate(orderDate,
			 * supId, custIdDeal, custIdAll, orderBy); } else { listTotal =
			 * supplierService.getAllTotalByDate(orderDate, supId, custIdAll,
			 * orderBy); }
			 * 
			 * for (int i = 0; i < listTotal.size(); i++) {
			 * 
			 * Object[] a = listTotal.get(i); HSSFRow row =
			 * sheet.createRow((int) i + 1);// 创建一行 row.setHeight((short)
			 * 340);// 行高
			 * 
			 * int totalDateLine = 0;
			 * 
			 * HSSFCell cell1 = row.createCell(totalDateLine);// 创建一列 材料Id
			 * cell1.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cell1.setCellValue(a[0].toString());
			 * cell1.setCellStyle(setBorder); totalDateLine = totalDateLine + 1;
			 * 
			 * HSSFCell cell3 = row.createCell(totalDateLine);// 创建一列 材料品级
			 * cell3.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cell3.setCellValue(a[1].toString());
			 * cell3.setCellStyle(setBorder); totalDateLine = totalDateLine + 1;
			 * 
			 * HSSFCell cell4 = row.createCell(totalDateLine);// 创建一列 供货商ID
			 * cell4.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cell4.setCellValue(a[2].toString());
			 * cell4.setCellStyle(setBorder); totalDateLine = totalDateLine + 1;
			 * 
			 * HSSFCell cell5 = row.createCell(totalDateLine);// 创建一列 供货商name
			 * cell5.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cell5.setCellValue(a[5].toString());
			 * cell5.setCellStyle(setBorder); totalDateLine = totalDateLine + 1;
			 * 
			 * HSSFCell cell7 = row.createCell(totalDateLine);// 创建一列 时间
			 * cell7.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cell7.setCellValue(orderDate); cell7.setCellStyle(setBorder);
			 * totalDateLine = totalDateLine + 1;
			 * 
			 * HSSFCell cell8 = row.createCell(totalDateLine);// 创建一列 每公斤价格
			 * cell8.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cell8.setCellStyle(setBorder); if (a[10] == null) {
			 * cell8.setCellValue(""); } else { BigDecimal materValue = new
			 * BigDecimal(a[10].toString()).multiply(new
			 * BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_UP);
			 * cell8.setCellValue(materValue.toString()); }
			 * 
			 * totalDateLine = totalDateLine + 1;
			 * 
			 * HSSFCell cell9 = row.createCell(totalDateLine);// 创建一列 总价格
			 * cell9.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cell9.setCellStyle(setBorder); cell9.setCellFormula("F" + (i + 2)
			 * + "*M" + (i + 2));
			 * 
			 * totalDateLine = totalDateLine + 1;
			 * 
			 * HSSFCell cell10 = row.createCell(totalDateLine);// 创建一列 种类
			 * cell10.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cell10.setCellValue(a[6].toString());
			 * cell10.setCellStyle(setBorder); totalDateLine = totalDateLine +
			 * 1;
			 * 
			 * HSSFCell cell12 = row.createCell(totalDateLine);// 创建一列 品牌
			 * cell12.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cell12.setCellValue(a[8].toString());
			 * cell12.setCellStyle(setBorder); totalDateLine = totalDateLine +
			 * 1;
			 * 
			 * HSSFCell cell13 = row.createCell(totalDateLine);// 创建一列 规格
			 * cell13.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cell13.setCellValue(a[9].toString());
			 * cell13.setCellStyle(setBorder); totalDateLine = totalDateLine +
			 * 1;
			 * 
			 * HSSFCell cell2 = row.createCell(totalDateLine);// 创建一列 材料名
			 * cell2.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cell2.setCellValue(a[4].toString());
			 * cell2.setCellStyle(setBorder); totalDateLine = totalDateLine + 1;
			 * 
			 * HSSFCell cell11 = row.createCell(totalDateLine);// 创建一列 单位
			 * cell11.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cell11.setCellValue(a[7].toString());
			 * cell11.setCellStyle(setBorder); totalDateLine = totalDateLine +
			 * 1;
			 * 
			 * HSSFCell cell6 = row.createCell(totalDateLine);// 创建一列
			 * cell6.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cell6.setCellValue(a[3].toString());
			 * cell6.setCellStyle(setBorder); totalDateLine = totalDateLine + 1;
			 * 
			 * 
			 * if (listCust != null && listCust.size() > 0) { for (int j = 0; j
			 * < listCust.size(); j++) { String custId =
			 * listCust.get(j)[0].toString(); String custName =
			 * listCust.get(j)[1].toString();
			 * 
			 * List<Object[]> listCustTotalDate = supplierService
			 * .getExcelCustTotalRealMaterByDateMaterIdMaterLevel(orderDate,
			 * supId, custId, a[0].toString(), a[1].toString()); if
			 * (listCustTotalDate != null && listCustTotalDate.size() > 0) {
			 * HSSFCell cellCustTotalDate = row.createCell(totalDateLine);//
			 * 创建一列 cellCustTotalDate.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * Object ad = (Object) listCustTotalDate.get(0);
			 * cellCustTotalDate.setCellValue(ad.toString());
			 * cellCustTotalDate.setCellStyle(setBorder); totalDateLine =
			 * totalDateLine + 1; } else { HSSFCell cellCustTotalDate =
			 * row.createCell(totalDateLine);// 创建一列
			 * cellCustTotalDate.setCellType(HSSFCell.CELL_TYPE_STRING);
			 * cellCustTotalDate.setCellValue("0");
			 * cellCustTotalDate.setCellStyle(setBorder); totalDateLine =
			 * totalDateLine + 1; } } }
			 * 
			 * }
			 */

			workbook.setSheetName(sheetIndex, "总表");
			sheetIndex = sheetIndex + 1;

			// 总表 分店显示材料数量

			// 生成店长需求sheet
			if (listCust != null && listCust.size() > 0) {
				for (int i = 0; i < listCust.size(); i++) {

					String custId = listCust.get(i)[0].toString();
					String custName = listCust.get(i)[1].toString();

					List<Object[]> listCustDate = supplierService.getExcelCustAllRealMaterByDate(orderDate, supId, custId);

					if (listCustDate != null && listCustDate.size() > 0) {
						System.out.println(i);
						// 初始行设置
						HSSFSheet sheetCust = workbook.createSheet();

						sheetCust.setColumnWidth(1, 4000);
						sheetCust.setColumnWidth(3, 4000);
						sheetCust.setColumnWidth(8, 4000);

						sheetCust.setColumnHidden(0, true);// 隐藏列
						sheetCust.setColumnHidden(2, true);// 隐藏列
						sheetCust.setColumnHidden(5, true);// 隐藏列

						HSSFRow rowCustfist = sheetCust.createRow(0);// 创建一行
						rowCustfist.setHeight((short) 340);// 行高

						int custTitleLine = 0;

						HSSFCell cellCustFirst1 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst1.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst1.setCellValue("店id");
						cellCustFirst1.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst2 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst2.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst2.setCellValue("店名");
						cellCustFirst2.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst3 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst3.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst3.setCellValue("材料Id");
						cellCustFirst3.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst4 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst4.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst4.setCellValue("材料名");
						cellCustFirst4.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst6 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst6.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst6.setCellValue("单位");
						cellCustFirst6.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst5 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst5.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst5.setCellValue("材料品级");
						cellCustFirst5.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst10 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst10.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst10.setCellValue("规格");
						cellCustFirst10.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						/*
						 * HSSFCell cellCustFirst6 =
						 * rowCustfist.createCell((int) 5);// 创建一列
						 * cellCustFirst6
						 * .setCellType(HSSFCell.CELL_TYPE_STRING);
						 * cellCustFirst6.setCellValue("供货商ID");
						 * cellCustFirst6.setCellStyle(setBorder);
						 */

						HSSFCell cellCustFirst7 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst7.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst7.setCellValue("需求重量");
						cellCustFirst7.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst8 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst8.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst8.setCellValue("实际送货重量");
						cellCustFirst8.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst9 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst9.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst9.setCellValue("价格");
						cellCustFirst9.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						for (int j = 0; j < listCustDate.size(); j++) {

							HSSFRow rowCustDate = sheetCust.createRow((int) j + 1);// 创建一行
							rowCustDate.setHeight((short) 340);// 行高

							int custDateLine = 0;
							HSSFCell cellCustDate1 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate1.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate1.setCellValue(custId);
							cellCustDate1.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate2 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate2.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate2.setCellValue(custName);
							cellCustDate2.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate3 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate3.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate3.setCellValue(listCustDate.get(j)[0].toString());
							cellCustDate3.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate4 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate4.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate4.setCellValue(listCustDate.get(j)[4].toString());
							cellCustDate4.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate9 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate9.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate9.setCellValue(listCustDate.get(j)[5].toString());
							cellCustDate9.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate5 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate5.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate5.setCellValue(listCustDate.get(j)[1].toString());
							cellCustDate5.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate10 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate10.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate10.setCellValue(listCustDate.get(j)[6].toString());
							cellCustDate10.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;
							/*
							 * HSSFCell cellCustDate6 =
							 * rowCustDate.createCell((int) 5);// 创建一列
							 * cellCustDate6
							 * .setCellType(HSSFCell.CELL_TYPE_STRING);
							 * cellCustDate6
							 * .setCellValue(listCustDate.get(j)[2].toString());
							 * cellCustDate6.setCellStyle(setBorder);
							 */

							HSSFCell cellCustDate7 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate7.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate7.setCellValue(listCustDate.get(j)[3].toString());
							cellCustDate7.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate8 = rowCustDate.createCell(custDateLine);// 实际送货数量
							cellCustDate8.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate8.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate11 = rowCustDate.createCell(custDateLine);// 价格
							cellCustDate11.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate11.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

						}
						workbook.setSheetName(sheetIndex, custName + "(" + (sheetIndex) + ")");
						sheetIndex = sheetIndex + 1;
					}
					// ----------------------
					/*
					 * HSSFSheet sheetCust = workbook.createSheet(); HSSFRow
					 * rowCust = sheetCust.createRow((int) i + 1);// 创建一行
					 * 
					 * HSSFCell cellCust1 = rowCust.createCell((int) 0);// 创建一列
					 * cellCust1.setCellType(HSSFCell.CELL_TYPE_STRING);
					 * cellCust1.setCellValue(listCust.get(i)[0].toString());
					 * cellCust1.setCellStyle(setBorder);
					 */
				}

			}
			sheet.setForceFormulaRecalculation(true);
			fOut = response.getOutputStream();
			workbook.write(fOut);
		} catch (UnsupportedEncodingException e1) {
		} catch (Exception e) {
		} finally {
			try {
				fOut.flush();
				fOut.close();
			} catch (IOException e) {
				json.put("success", false);
			}
			session.setAttribute("state", "open");
		}

		json.put("success", true);
		return json.toString();
	}

	// 导出excel方法
	@RequestMapping(value = "/exportSupperExcelPrint.do", method = { RequestMethod.POST })
	@ResponseBody
	public String exportSupperExcelPrint(HttpServletRequest request, HttpServletResponse response, HttpSession session1, String orderDate, int supId)
			throws Exception {
		JSONObject json = new JSONObject();
		HttpSession session = request.getSession();
		session.setAttribute("state", null);
		// 生成提示信息，
		// String codedFileName = null;
		// OutputStream fOut = null;
		UserPo userInfo = (UserPo) session1.getAttribute("user");

		// 增加对时间的校验
		boolean flagTime = false;
		try {
			flagTime = timeControlService.timeControl(userInfo.getUserId(), orderDate);
		} catch (Exception e2) {
			e2.printStackTrace();
		}
		if (!flagTime && supId == 0) {
			json.put("msg", "msg001");

			json.put("success", false);
			return json.toString();
		}
		// 根据用户id得出supid
		if (supId == 0) {
			supId = supplierService.getSupIdByUserId(userInfo.getUserId());
		}
		boolean lockFlag = lockTransService.lockTrans("exportSupperExcelPrint.do", supId);
		if (!lockFlag) {
			json.put("msg", "locked");
			json.put("success", false);
			return json.toString();
		}
		try {
			// response.setContentType("application/vnd.ms-excel");
			// 进行转码，使其支持中文文件名
			// codedFileName = java.net.URLEncoder.encode("deliveries" + supId +
			// "_" + PubFun.getCurrentDate(),"UTF-8");
			// codedFileName = new String("送货单".getBytes("GBK"), "ISO8859-1");
			// response.setHeader("content-disposition", "attachment;filename="
			// + codedFileName + "_"
			// + orderDate + ".xls");
			// response.addHeader("Content-Disposition",
			// "attachment;   filename=" + codedFileName + ".xls");
			// 产生工作簿对象
			HSSFWorkbook workbook = new HSSFWorkbook();
			// 产生工作表对象

			HSSFSheet sheet = workbook.createSheet();

			// 设定自动适应列宽
			for (int i = 0; i < 20; i++) {
				sheet.autoSizeColumn(i);
			}
			// 边框
			HSSFCellStyle titleStyle = workbook.createCellStyle();
			titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
			titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);

			HSSFFont font = workbook.createFont();
			font.setFontName("宋体");
			font.setFontHeightInPoints((short) 20);
			titleStyle.setFont(font);
			// 边框
			HSSFCellStyle setBorder = workbook.createCellStyle();
			setBorder.setWrapText(true); // 自动换行
			setBorder.setVerticalAlignment(setBorder.VERTICAL_CENTER);// 垂直居中
			setBorder.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
			setBorder.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
			setBorder.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
			setBorder.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
			setBorder.setAlignment(HSSFCellStyle.VERTICAL_CENTER);
			// 货币
			HSSFCellStyle cellStyle = workbook.createCellStyle();
			HSSFDataFormat format = workbook.createDataFormat();
			cellStyle.setDataFormat(format.getFormat("¥#,##0.00"));

			cellStyle.setVerticalAlignment(cellStyle.VERTICAL_CENTER);// 垂直居中

			cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
			cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
			cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
			cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
			cellStyle.setAlignment(HSSFCellStyle.VERTICAL_CENTER);

			// 小数
			HSSFCellStyle cellStyleNumber = workbook.createCellStyle();
			cellStyleNumber.setDataFormat(format.getFormat("0.00"));
			cellStyleNumber.setVerticalAlignment(cellStyleNumber.VERTICAL_CENTER);// 垂直居中

			cellStyleNumber.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
			cellStyleNumber.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
			cellStyleNumber.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
			cellStyleNumber.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
			cellStyleNumber.setAlignment(HSSFCellStyle.VERTICAL_CENTER);

			int sheetIndex = 0;
			workbook.setSheetName(sheetIndex, "总表");
			sheetIndex = sheetIndex + 1;
			// 总表的分表标题
			List<Object[]> listCust = supplierService.getExcelCust(orderDate, supId);

			// 总表 分店显示材料数量

			// 生成店长需求sheet
			if (listCust != null && listCust.size() > 0) {
				for (int i = 0; i < listCust.size(); i++) {

					String custId = listCust.get(i)[0].toString();
					String custName = listCust.get(i)[1].toString();

					List<Object[]> listCustDateCheck = supplierService.getExcelCustAllRealMaterByDate(orderDate, supId, custId);
					List<Object[]> listCustDate = supplierService.getExcelCustAllRealMaterByDateForPrint(orderDate, supId, custId);

					if (listCustDate == null || listCustDateCheck.size() != listCustDate.size()) {
						json.put("success", false);
						json.put("msg", "msg0001");
						return json.toString();
					}
					if (listCustDate != null && listCustDate.size() > 0) {
						// 初始行设置
						HSSFSheet sheetCust = workbook.createSheet();

						sheetCust.setColumnWidth(0, 1200);
						sheetCust.setColumnWidth(2, 4000);
						sheetCust.setColumnWidth(4, 4000);
						sheetCust.setColumnWidth(5, 1500);
						sheetCust.setColumnWidth(8, 4000);
						sheetCust.setColumnWidth(9, 1800);
						sheetCust.setColumnWidth(10, 1800);
						sheetCust.setColumnWidth(13, 3000);

						sheetCust.setColumnHidden(1, true);// 隐藏列
						sheetCust.setColumnHidden(3, true);// 隐藏列
						sheetCust.setColumnHidden(7, true);// 隐藏列
						sheetCust.setColumnHidden(12, true);// 隐藏列

						sheetCust.setMargin(HSSFSheet.TopMargin, (double) 0.3);// 页边距（上）
						sheetCust.setMargin(HSSFSheet.BottomMargin, (double) 0.3);// 页边距（下）
						sheetCust.setMargin(HSSFSheet.LeftMargin, (double) 0.3);// 页边距（左）
						sheetCust.setMargin(HSSFSheet.RightMargin, (double) 0.3);// 页边距（右
						sheetCust.setHorizontallyCenter(true);// 打印水平居中
						HSSFRow rowTitlefist = sheetCust.createRow(0);// 创建首航行
						rowTitlefist.setHeight((short) 800);// 行高

						sheetCust.addMergedRegion(new CellRangeAddress(0, 0, 0, 13));

						HSSFCell cell_1 = rowTitlefist.createCell(0);

						supplierService.getSupPoBySupId(supId);
						cell_1.setCellValue(supplierService.getSupPoBySupId(supId).getCompanyName() + "送货单");
						cell_1.setCellStyle(titleStyle);

						HSSFRow rowCustfist = sheetCust.createRow(1);// 创建标题行
						int custTitleLine = 0;

						HSSFCell cellCustFirst0 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst0.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst0.setCellValue("序号");
						cellCustFirst0.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst1 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst1.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst1.setCellValue("店id");
						cellCustFirst1.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst2 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst2.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst2.setCellValue("店名");
						cellCustFirst2.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst3 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst3.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst3.setCellValue("材料Id");
						cellCustFirst3.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst4 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst4.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst4.setCellValue("材料名");
						cellCustFirst4.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst6 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst6.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst6.setCellValue("单位");
						cellCustFirst6.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst13 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst13.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst13.setCellValue("种类");
						cellCustFirst13.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst5 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst5.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst5.setCellValue("材料品级");
						cellCustFirst5.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst10 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst10.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst10.setCellValue("规格");
						cellCustFirst10.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst7 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst7.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst7.setCellValue("需求量");
						cellCustFirst7.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst8 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst8.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst8.setCellValue("实送量");
						cellCustFirst8.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst9 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst9.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst9.setCellValue("单位价格");
						cellCustFirst9.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst11 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst11.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst11.setCellValue("需求价格");
						cellCustFirst11.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst12 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst12.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst12.setCellValue("实际价格");
						cellCustFirst12.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						int serialNumber = 1;
						for (int j = 0; j < listCustDate.size(); j++) {
							Float hieght = new Float(0.01F);// 计算行高的变量
							Float hieghtCompare = new Float(0.01F);// 计算行高的变量

							HSSFRow rowCustDate = sheetCust.createRow((int) j + 2);// 创建一行
							rowCustDate.setHeight((short) 340);// 行高

							int custDateLine = 0;

							HSSFCell cellCustDate0 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate0.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate0.setCellValue(serialNumber);
							serialNumber++;
							cellCustDate0.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate1 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate1.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate1.setCellValue(custId);
							cellCustDate1.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate2 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate2.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate2.setCellValue(custName);
							cellCustDate2.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							// 设置高度
							hieghtCompare = getExcelCellAutoHeight(custName, 8f);
							if (hieght.compareTo(hieghtCompare) < 0) {
								hieght = hieghtCompare;
							}

							HSSFCell cellCustDate3 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate3.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate3.setCellValue(listCustDate.get(j)[0].toString());
							cellCustDate3.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate4 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate4.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate4.setCellValue(listCustDate.get(j)[4].toString());
							cellCustDate4.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							// 设置高度
							hieghtCompare = getExcelCellAutoHeight(listCustDate.get(j)[4].toString(), 8f);
							if (hieght.compareTo(hieghtCompare) < 0) {
								hieght = hieghtCompare;
							}

							HSSFCell cellCustDate9 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate9.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate9.setCellValue(listCustDate.get(j)[5].toString());
							cellCustDate9.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate14 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate14.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate14.setCellValue(listCustDate.get(j)[9].toString());
							cellCustDate14.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate5 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate5.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate5.setCellValue(listCustDate.get(j)[1].toString());
							cellCustDate5.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate10 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate10.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate10.setCellValue(listCustDate.get(j)[6].toString());
							cellCustDate10.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate7 = rowCustDate.createCell(custDateLine);// 需求量
							cellCustDate7.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate7.setCellValue(listCustDate.get(j)[10].toString());
							cellCustDate7.setCellStyle(cellStyleNumber);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate8 = rowCustDate.createCell(custDateLine);// 实际送货数量
							cellCustDate8.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate8.setCellStyle(cellStyleNumber);
							cellCustDate8.setCellValue(listCustDate.get(j)[3].toString());
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate11 = rowCustDate.createCell(custDateLine);// 单位价格
							cellCustDate11.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate11.setCellValue(listCustDate.get(j)[7].toString());
							cellCustDate11.setCellStyle(cellStyle);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate12 = rowCustDate.createCell(custDateLine);// 需求价格
							cellCustDate12.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate12.setCellFormula("J" + (j + 3) + "*L" + (j + 3));
							cellCustDate12.setCellStyle(cellStyle);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate13 = rowCustDate.createCell(custDateLine);// 实际价格
							cellCustDate13.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate13.setCellStyle(cellStyle);
							cellCustDate13.setCellFormula("K" + (j + 3) + "*L" + (j + 3));
							custDateLine = custDateLine + 1;

							// 根据字符串的长度设置高度
							sheetCust.getRow(sheetCust.getLastRowNum()).setHeightInPoints(hieght);
						}
						workbook.setSheetName(sheetIndex, custName + "(" + (sheetIndex) + ")");
						sheetIndex = sheetIndex + 1;
						// 总价格显示
						HSSFRow rowCustLast = sheetCust.createRow(listCustDate.size() + 2);// 创建一行
						rowCustLast.setHeight((short) 340);// 行高

						int custLastLine = 0;

						HSSFCell cellCustLast0 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast0.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast0.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast1 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast1.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast1.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast2 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast2.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast2.setCellValue("送货时间");
						cellCustLast2.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast3 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast3.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast3.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast4 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast4.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast4.setCellValue(orderDate);// 订单时间
						cellCustLast4.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast6 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast6.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast6.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast5 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast5.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast5.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast10 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast10.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast10.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast14 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast14.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast14.setCellStyle(setBorder);
						cellCustLast14.setCellValue("送货人签字");
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast7 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast7.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast7.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast8 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast8.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast8.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast9 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast9.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast9.setCellValue("合计");
						cellCustLast9.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast11 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast11.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast11.setCellFormula("SUM(M3:M" + (listCustDate.size() + 2) + ")");
						cellCustLast11.setCellStyle(cellStyle);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast12 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast12.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast12.setCellFormula("SUM(N3:N" + (listCustDate.size() + 2) + ")");
						cellCustLast12.setCellStyle(cellStyle);
						custLastLine = custLastLine + 1;
					}

				}

			}
			workbook.removeSheetAt(workbook.getSheetIndex("总表"));

			// fOut = response.getOutputStream();
			// workbook.write(fOut);

			InputStream excelStream = null;

			ByteArrayOutputStream out = new ByteArrayOutputStream();

			HSSFWorkbook hssWb = (HSSFWorkbook) workbook;

			hssWb.write(out);

			excelStream = new ByteArrayInputStream(out.toByteArray());

			out.close();

			String realPath = session1.getServletContext().getRealPath("/");

			String filePath = realPath + File.separator + "jsp" + File.separator + "templet" + File.separator + "excelSupperLookPrint";

			FileUtill.saveFileFromInputStream(excelStream, filePath, supId + "_" + "送货单" + "_" + orderDate + ".xls");

		} catch (Exception e) {

		} finally {
			lockTransService.unlockTrans("exportSupperExcelPrint.do", supId);
			// try {
			// fOut.flush();
			// fOut.close();
			// } catch (IOException e) {
			// json.put("success", false);
			// }
			// session.setAttribute("state", "open");
		}

		json.put("success", true);
		return json.toString();
	}

	@RequestMapping(value = "/exportSupperExcelPrintDown.do", method = { RequestMethod.POST })
	@ResponseBody
	public String exportSupperExcelPrintDown(HttpServletRequest request, HttpServletResponse response, HttpSession session1, String orderDate,
			int supId) throws Exception {
		JSONObject json = new JSONObject();

		UserPo userInfo = (UserPo) session1.getAttribute("user");
		// 根据用户id得出supid
		if (supId == 0) {
			supId = supplierService.getSupIdByUserId(userInfo.getUserId());
		}

		boolean lockFlag = lockTransService.lockTrans("exportSupperExcelPrint.do", supId);
		if (!lockFlag) {
			json.put("msg", "locked");
			json.put("success", false);
			return json.toString();
		}
		OutputStream toClient = null;
		try {

			String filename = supId + "_" + "送货单" + "_" + orderDate + ".xls";
			// 以流的形式下载文件。
			String realPath = session1.getServletContext().getRealPath("/");
			String filePath = realPath + File.separator + "jsp" + File.separator + "templet" + File.separator + "excelSupperLookPrint"
					+ File.separator;
			InputStream fis = new BufferedInputStream(new FileInputStream(filePath + filename));
			byte[] buffer = new byte[fis.available()];
			fis.read(buffer);
			fis.close();
			// 清空response
			response.reset();
			// 设置response的Header
			// response.addHeader("Content-Disposition", "attachment;filename="
			// + new String(filename.getBytes()));

			response.setContentType("octets/stream");
			response.addHeader("Content-Type", "text/html; charset=utf-8");
			String downLoadName = new String(filename.getBytes("gbk"), "iso8859-1");
			response.addHeader("Content-Disposition", "attachment;filename=" + downLoadName);

			toClient = new BufferedOutputStream(response.getOutputStream());
			toClient.write(buffer);
		} catch (Exception e) {
		} finally {
			lockTransService.unlockTrans("exportSupperExcelPrint.do", supId);
			try {
				toClient.flush();
				toClient.close();
			} catch (IOException e) {
			}
		}
		json.put("msg", "msg001");
		json.put("success", false);
		return json.toString();
	}

	// 送货表(进货价格)
	@RequestMapping(value = "/exportSupperExcelPrintCost.do", method = { RequestMethod.POST })
	@ResponseBody
	public String exportSupperExcelPrintCost(HttpServletRequest request, HttpServletResponse response, HttpSession session1, String orderDate,
			int supId) {
		JSONObject json = new JSONObject();
		HttpSession session = request.getSession();
		session.setAttribute("state", null);
		// 生成提示信息，
		String codedFileName = null;
		OutputStream fOut = null;
		UserPo userInfo = (UserPo) session1.getAttribute("user");

		// 增加对时间的校验
		boolean flagTime = false;
		try {
			flagTime = timeControlService.timeControl(userInfo.getUserId(), orderDate);
		} catch (Exception e2) {
			e2.printStackTrace();
		}
		if (!flagTime && supId == 0) {
			json.put("msg", "msg001");

			json.put("success", false);
			return json.toString();
		}

		try {

			response.setContentType("application/vnd.ms-excel");

			// 根据用户id得出supid

			if (supId == 0) {
				supId = supplierService.getSupIdByUserId(userInfo.getUserId());
			}
			// 进行转码，使其支持中文文件名
			// codedFileName = java.net.URLEncoder.encode("deliveries" + supId +
			// "_" + PubFun.getCurrentDate(),"UTF-8");
			codedFileName = new String("送货单".getBytes("GBK"), "ISO8859-1");
			response.setHeader("content-disposition", "attachment;filename=" + codedFileName + "_" + orderDate + ".xls");
			// response.addHeader("Content-Disposition",
			// "attachment;   filename=" + codedFileName + ".xls");
			// 产生工作簿对象
			HSSFWorkbook workbook = new HSSFWorkbook();
			// 产生工作表对象

			HSSFSheet sheet = workbook.createSheet();

			// 设定自动适应列宽
			for (int i = 0; i < 20; i++) {
				sheet.autoSizeColumn(i);
			}
			// 边框
			HSSFCellStyle titleStyle = workbook.createCellStyle();
			titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直居中
			titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);

			HSSFFont font = workbook.createFont();
			font.setFontName("宋体");
			font.setFontHeightInPoints((short) 20);
			titleStyle.setFont(font);
			// 边框
			HSSFCellStyle setBorder = workbook.createCellStyle();
			setBorder.setWrapText(true); // 自动换行
			setBorder.setVerticalAlignment(setBorder.VERTICAL_CENTER);// 垂直居中
			setBorder.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
			setBorder.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
			setBorder.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
			setBorder.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
			setBorder.setAlignment(HSSFCellStyle.VERTICAL_CENTER);
			// 货币
			HSSFCellStyle cellStyle = workbook.createCellStyle();
			HSSFDataFormat format = workbook.createDataFormat();
			cellStyle.setDataFormat(format.getFormat("¥#,##0.00"));

			cellStyle.setVerticalAlignment(cellStyle.VERTICAL_CENTER);// 垂直居中

			cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
			cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
			cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
			cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
			cellStyle.setAlignment(HSSFCellStyle.VERTICAL_CENTER);

			// 小数
			HSSFCellStyle cellStyleNumber = workbook.createCellStyle();
			cellStyleNumber.setDataFormat(format.getFormat("0.00"));
			cellStyleNumber.setVerticalAlignment(cellStyleNumber.VERTICAL_CENTER);// 垂直居中

			cellStyleNumber.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
			cellStyleNumber.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
			cellStyleNumber.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
			cellStyleNumber.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
			cellStyleNumber.setAlignment(HSSFCellStyle.VERTICAL_CENTER);

			int sheetIndex = 0;
			workbook.setSheetName(sheetIndex, "总表");
			sheetIndex = sheetIndex + 1;
			// 总表的分表标题
			List<Object[]> listCust = supplierService.getExcelCust(orderDate, supId);

			// 总表 分店显示材料数量

			// 生成店长需求sheet
			if (listCust != null && listCust.size() > 0) {
				for (int i = 0; i < listCust.size(); i++) {

					String custId = listCust.get(i)[0].toString();
					String custName = listCust.get(i)[1].toString();

					/*
					 * List<Object[]> listCustDateCheck =
					 * supplierService.getExcelCustAllRealMaterByDate(
					 * orderDate, supId, custId);
					 */
					List<Object[]> listCustDate = supplierService.getExcelCustAllRealMaterByDateForPrintCost(orderDate, supId, custId);

					/*
					 * if (listCustDate == null || listCustDateCheck.size() !=
					 * listCustDate.size()) { json.put("success", false);
					 * json.put("msg", "msg0001"); return json.toString(); }
					 */
					if (listCustDate != null && listCustDate.size() > 0) {
						// 初始行设置
						HSSFSheet sheetCust = workbook.createSheet();

						sheetCust.setColumnWidth(0, 1200);
						sheetCust.setColumnWidth(2, 4000);
						sheetCust.setColumnWidth(4, 4000);
						sheetCust.setColumnWidth(5, 1500);
						sheetCust.setColumnWidth(8, 4000);
						sheetCust.setColumnWidth(9, 1800);
						sheetCust.setColumnWidth(10, 1800);
						sheetCust.setColumnWidth(13, 3000);

						sheetCust.setColumnHidden(1, true);// 隐藏列
						sheetCust.setColumnHidden(3, true);// 隐藏列
						sheetCust.setColumnHidden(7, true);// 隐藏列
						sheetCust.setColumnHidden(12, true);// 隐藏列

						sheetCust.setMargin(HSSFSheet.TopMargin, (double) 0.3);// 页边距（上）
						sheetCust.setMargin(HSSFSheet.BottomMargin, (double) 0.3);// 页边距（下）
						sheetCust.setMargin(HSSFSheet.LeftMargin, (double) 0.3);// 页边距（左）
						sheetCust.setMargin(HSSFSheet.RightMargin, (double) 0.3);// 页边距（右
						sheetCust.setHorizontallyCenter(true);// 打印水平居中
						HSSFRow rowTitlefist = sheetCust.createRow(0);// 创建首航行
						rowTitlefist.setHeight((short) 800);// 行高

						sheetCust.addMergedRegion(new CellRangeAddress(0, 0, 0, 10));

						HSSFCell cell_1 = rowTitlefist.createCell(0);

						supplierService.getSupPoBySupId(supId);
						cell_1.setCellValue(supplierService.getSupPoBySupId(supId).getCompanyName() + "送货单");
						cell_1.setCellStyle(titleStyle);

						HSSFRow rowCustfist = sheetCust.createRow(1);// 创建标题行
						int custTitleLine = 0;

						HSSFCell cellCustFirst0 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst0.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst0.setCellValue("序号");
						cellCustFirst0.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst1 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst1.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst1.setCellValue("店id");
						cellCustFirst1.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst2 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst2.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst2.setCellValue("店名");
						cellCustFirst2.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst3 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst3.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst3.setCellValue("材料Id");
						cellCustFirst3.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst4 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst4.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst4.setCellValue("材料名");
						cellCustFirst4.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst6 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst6.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst6.setCellValue("单位");
						cellCustFirst6.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst13 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst13.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst13.setCellValue("种类");
						cellCustFirst13.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst5 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst5.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst5.setCellValue("材料品级");
						cellCustFirst5.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst10 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst10.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst10.setCellValue("规格");
						cellCustFirst10.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst7 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst7.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst7.setCellValue("需求量");
						cellCustFirst7.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						HSSFCell cellCustFirst8 = rowCustfist.createCell(custTitleLine);// 创建一列
						cellCustFirst8.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustFirst8.setCellValue("实送量");
						cellCustFirst8.setCellStyle(setBorder);
						custTitleLine = custTitleLine + 1;

						/*
						 * HSSFCell cellCustFirst9 =
						 * rowCustfist.createCell(custTitleLine);// 创建一列
						 * cellCustFirst9
						 * .setCellType(HSSFCell.CELL_TYPE_STRING);
						 * cellCustFirst9.setCellValue("单位价格");
						 * cellCustFirst9.setCellStyle(setBorder); custTitleLine
						 * = custTitleLine + 1;
						 * 
						 * HSSFCell cellCustFirst11 =
						 * rowCustfist.createCell(custTitleLine);// 创建一列
						 * cellCustFirst11
						 * .setCellType(HSSFCell.CELL_TYPE_STRING);
						 * cellCustFirst11.setCellValue("需求价格");
						 * cellCustFirst11.setCellStyle(setBorder);
						 * custTitleLine = custTitleLine + 1;
						 * 
						 * HSSFCell cellCustFirst12 =
						 * rowCustfist.createCell(custTitleLine);// 创建一列
						 * cellCustFirst12
						 * .setCellType(HSSFCell.CELL_TYPE_STRING);
						 * cellCustFirst12.setCellValue("实际价格");
						 * cellCustFirst12.setCellStyle(setBorder);
						 * custTitleLine = custTitleLine + 1;
						 */

						int serialNumber = 1;
						for (int j = 0; j < listCustDate.size(); j++) {
							Float hieght = new Float(0.01F);// 计算行高的变量
							Float hieghtCompare = new Float(0.01F);// 计算行高的变量

							HSSFRow rowCustDate = sheetCust.createRow((int) j + 2);// 创建一行
							rowCustDate.setHeight((short) 340);// 行高

							int custDateLine = 0;

							HSSFCell cellCustDate0 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate0.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate0.setCellValue(serialNumber);
							serialNumber++;
							cellCustDate0.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate1 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate1.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate1.setCellValue(custId);
							cellCustDate1.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate2 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate2.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate2.setCellValue(custName);
							cellCustDate2.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							// 设置高度
							hieghtCompare = getExcelCellAutoHeight(custName, 8f);
							if (hieght.compareTo(hieghtCompare) < 0) {
								hieght = hieghtCompare;
							}

							HSSFCell cellCustDate3 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate3.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate3.setCellValue(listCustDate.get(j)[0].toString());
							cellCustDate3.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate4 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate4.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate4.setCellValue(listCustDate.get(j)[4].toString());
							cellCustDate4.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							// 设置高度
							hieghtCompare = getExcelCellAutoHeight(listCustDate.get(j)[4].toString(), 8f);
							if (hieght.compareTo(hieghtCompare) < 0) {
								hieght = hieghtCompare;
							}

							HSSFCell cellCustDate9 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate9.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate9.setCellValue(listCustDate.get(j)[5].toString());
							cellCustDate9.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate14 = rowCustDate.createCell(custDateLine);// 种类
							cellCustDate14.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate14.setCellValue(listCustDate.get(j)[7].toString());
							cellCustDate14.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate5 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate5.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate5.setCellValue(listCustDate.get(j)[1].toString());
							cellCustDate5.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate10 = rowCustDate.createCell(custDateLine);// 创建一列
							cellCustDate10.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate10.setCellValue(listCustDate.get(j)[6].toString());
							cellCustDate10.setCellStyle(setBorder);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate7 = rowCustDate.createCell(custDateLine);// 需求量
							cellCustDate7.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate7.setCellValue(listCustDate.get(j)[3].toString());
							cellCustDate7.setCellStyle(cellStyleNumber);
							custDateLine = custDateLine + 1;

							HSSFCell cellCustDate8 = rowCustDate.createCell(custDateLine);// 实际送货数量
							cellCustDate8.setCellType(HSSFCell.CELL_TYPE_STRING);
							cellCustDate8.setCellStyle(cellStyleNumber);
							cellCustDate8.setCellValue(listCustDate.get(j)[3].toString());
							custDateLine = custDateLine + 1;

							// 根据字符串的长度设置高度
							sheetCust.getRow(sheetCust.getLastRowNum()).setHeightInPoints(hieght);
						}
						workbook.setSheetName(sheetIndex, custName + "(" + (sheetIndex) + ")");
						sheetIndex = sheetIndex + 1;
						// 总价格显示
						HSSFRow rowCustLast = sheetCust.createRow(listCustDate.size() + 2);// 创建一行
						rowCustLast.setHeight((short) 340);// 行高

						int custLastLine = 0;

						HSSFCell cellCustLast0 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast0.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast0.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast1 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast1.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast1.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast2 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast2.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast2.setCellValue("送货时间");
						cellCustLast2.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast3 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast3.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast3.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast4 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast4.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast4.setCellValue(orderDate);// 订单时间
						cellCustLast4.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast6 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast6.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast6.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast5 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast5.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast5.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast10 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast10.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast10.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast7 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast7.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast7.setCellStyle(setBorder);
						cellCustLast7.setCellValue("送货人签字");
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast8 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast8.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast8.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						HSSFCell cellCustLast13 = rowCustLast.createCell(custLastLine);// 创建一列
						cellCustLast13.setCellType(HSSFCell.CELL_TYPE_STRING);
						cellCustLast13.setCellStyle(setBorder);
						custLastLine = custLastLine + 1;

						/*
						 * HSSFCell cellCustLast9 =
						 * rowCustLast.createCell(custLastLine);// 创建一列
						 * cellCustLast9.setCellType(HSSFCell.CELL_TYPE_STRING);
						 * cellCustLast9.setCellValue("合计");
						 * cellCustLast9.setCellStyle(setBorder); custLastLine =
						 * custLastLine + 1;
						 * 
						 * HSSFCell cellCustLast11 =
						 * rowCustLast.createCell(custLastLine);// 创建一列
						 * cellCustLast11
						 * .setCellType(HSSFCell.CELL_TYPE_STRING);
						 * cellCustLast11.setCellFormula("SUM(M3:M" +
						 * (listCustDate.size() + 2) + ")");
						 * cellCustLast11.setCellStyle(cellStyle); custLastLine
						 * = custLastLine + 1;
						 * 
						 * HSSFCell cellCustLast12 =
						 * rowCustLast.createCell(custLastLine);// 创建一列
						 * cellCustLast12
						 * .setCellType(HSSFCell.CELL_TYPE_STRING);
						 * cellCustLast12.setCellFormula("SUM(N3:N" +
						 * (listCustDate.size() + 2) + ")");
						 * cellCustLast12.setCellStyle(cellStyle); custLastLine
						 * = custLastLine + 1;
						 */
					}

				}

			}
			workbook.removeSheetAt(workbook.getSheetIndex("总表"));

			fOut = response.getOutputStream();
			workbook.write(fOut);
		} catch (UnsupportedEncodingException e1) {
		} catch (Exception e) {
		} finally {
			try {
				fOut.flush();
				fOut.close();
			} catch (IOException e) {
				json.put("success", false);
			}
			session.setAttribute("state", "open");
		}

		json.put("success", true);
		return json.toString();
	}

	// 导入出库价格
	@RequestMapping(value = "/importSupMaterValue.do", method = { RequestMethod.POST })
	@ResponseBody
	public String importSupMaterValue(ExcelVo excelVo, HttpServletRequest request, HttpServletResponse response, HttpSession session)
			throws Exception {

		JSONObject json1 = new JSONObject();
		// 事物锁
		UserPo lgUser = (UserPo) session.getAttribute("user");
		int supId = supplierService.getSupIdByUserId(lgUser.getUserId());
		boolean lockFlag = lockTransService.lockTrans("importSupMaterValue.do", supId);
		if (!lockFlag) {
			json1.put("msg", "locked");
			json1.put("success", false);
			return json1.toString();
		}
		// 事务锁over
		try {

			MultipartFile filename = excelVo.getFilename();

			String temp = request.getSession().getServletContext().getRealPath(File.separator) + "temp"; // 临时目录
			File tempFile = new File(temp);
			if (!tempFile.exists()) {
				tempFile.mkdirs();
			}
			DiskFileUpload fu = new DiskFileUpload();
			fu.setSizeMax(10 * 1024 * 1024); // 设置允许用户上传文件大小,单位:位
			fu.setSizeThreshold(4096); // 设置最多只允许在内存中存储的数据,单位:位
			fu.setRepositoryPath(temp); // 设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录
			// 开始读取上传信息
			// int index = 0;
			if (filename == null)
				return null;

			String name = filename.getOriginalFilename();// 获取上传文件名,包括路径
			// name = name.substring(name.lastIndexOf("\\") + 1);// 从全路径中提取文件名
			long size = filename.getSize();
			if ((name == null || name.equals("")) && size == 0) {
				json1.put("msg", "msg001");
				json1.put("success", false);
				return json1.toString();
			}
			InputStream in = filename.getInputStream();

			ExcelReader excelReader = new ExcelReader();
			String[] title = excelReader.readExcelTitle(in);
			// System.out.println("获得Excel表格的标题:");
			for (String s : title) {
				System.out.print(s + " ");
			}

			// 对读取Excel表格内容测试
			Map<Integer, String> map = excelReader.readExcelContent(in, "*");

			boolean flag = false;
			try {
				flag = supplierService.importSupMaterValue(map, excelVo.getCustIdAll());
				String[] everyline = map.get(1).split("\\*");
				supplierService.computeTotalValue(everyline[4], Integer.valueOf(new BigDecimal(everyline[2]).intValue()), 0);
			} catch (Exception e) {
				json1.put("msg", supplierService.getMsg());
				flag = false;
			}

			if (flag) {
				json1.put("success", true);
			} else {
				json1.put("msg", supplierService.getMsg());
				json1.put("success", false);
			}
		} catch (Exception e) {
			json1.put("msg", "exception");
			json1.put("success", false);
			return json1.toString();
		} finally {
			// 解锁
			lockTransService.unlockTrans("importSupMaterValue.do", supId);
		}
		return json1.toString();

	}

	@RequestMapping(value = "/importSupMaterValueForWeb.do", method = { RequestMethod.POST })
	@ResponseBody
	public String importSupMaterValueForWeb(MaterVo materVo, HttpServletRequest request, HttpServletResponse response, HttpSession session)
			throws Exception {
		JSONObject json1 = new JSONObject();
		UserPo lgUser = (UserPo) session.getAttribute("user");
		int supId = supplierService.getSupIdByUserId(lgUser.getUserId());

		// 事物锁
		boolean lockFlag = lockTransService.lockTrans("importSupMaterValueForWeb.do", supId);
		if (!lockFlag) {
			json1.put("msg", "locked");
			json1.put("success", false);
			return json1.toString();
		}

		materVo.setSupId(supId);
		boolean flag = false;
		try {
			flag = supplierService.importSupMaterValueForWeb(materVo);
			supplierService.computeTotalValue(materVo.getDate(), materVo.getSupId(), materVo.getOrdId());

			// sendmater 状态
			OrderSupplierPo orderSupplierPo = new OrderSupplierPo();
			orderSupplierPo = supplierOrderService.getOrderSup(String.valueOf(materVo.getOrdId()), String.valueOf(materVo.getCustId()),
					String.valueOf(supId));
			supplierOrderService.sendmater(orderSupplierPo);

			// 自动生成出库单
			// 先判断 是否存在 订单相同的 出库单
			StoreOutVo storeOutVo = new StoreOutVo();
			List<StoreOutPo> tStoreOutPoList = storeService.getStoreOutPoBySupIdAndOrdId(supId, materVo.getOrdId());
			if (tStoreOutPoList != null && tStoreOutPoList.size() > 0) {
				storeOutVo.setStoreOutId(tStoreOutPoList.get(0).getStoreOutId());
				storeService.deleteStoreOutdetail(storeOutVo);
				storeService.minStoreOutDetailedForSup(materVo.getMaterJson(), tStoreOutPoList.get(0));
			} else {
				int storeHouseId = storeService.getStoreHouseIdBySupId(supId);
				storeOutVo.setMaterdategridList(materVo.getMaterJson());
				storeOutVo.setCreatDate(materVo.getDate());
				storeOutVo.setStoreHouseId(storeHouseId);
				storeOutVo.setStoreOutState(1);// 状态未确认
				storeOutVo.setStoreOutWay(0);// 自动出库
				storeOutVo.setOrdId(materVo.getOrdId());
				storeOutVo.setSupId(supId);// 供货商
				storeOutVo.setCustId(materVo.getCustId());
				StoreOutPo storeOutPo = storeService.minStoreOutForSup(storeOutVo);
				storeOutVo.setStoreOutId(storeOutPo.getStoreOutId());
				storeService.minStoreOutDetailedForSup(storeOutVo.getMaterdategridList(), storeOutPo);
			}

		} catch (Exception e) {
			json1.put("msg", supplierService.getMsg());
			flag = false;
		} finally {
			// 解锁
			lockTransService.unlockTrans("importSupMaterValueForWeb.do", supId);
		}
		if (flag) {
			json1.put("success", true);
		} else {
			json1.put("msg", supplierService.getMsg());
			json1.put("success", false);
		}
		return json1.toString();
	}

	@RequestMapping(value = "/importSupMaterValueCostForWeb.do", method = { RequestMethod.POST })
	@ResponseBody
	public String importSupMaterValueCostForWeb(MaterVo materVo, HttpSession session) throws Exception {
		JSONObject json1 = new JSONObject();
		UserPo lgUser = (UserPo) session.getAttribute("user");
		int supId = supplierService.getSupIdByUserId(lgUser.getUserId());

		// 事物锁
		boolean lockFlag = lockTransService.lockTrans("importSupMaterValueCostForWeb.do", supId);
		/*
		 * if (!lockFlag) { json1.put("msg", "locked"); json1.put("success",
		 * false); return json1.toString(); }
		 */
		// System.out.println(PubFun.getCurrentTime());
		materVo.setSupId(supId);
		boolean flag = false;
		try {
			flag = supplierService.importSupMaterValueCostForWeb(materVo);
			// supplierService.computeTotalValue(materVo.getDate(),
			// materVo.getSupId());
		} catch (Exception e) {
			json1.put("msg", supplierService.getMsg());
			flag = false;
		} finally {
			// 解锁
			lockTransService.unlockTrans("importSupMaterValueCostForWeb.do", supId);
		}
		if (flag) {
			json1.put("success", true);
		} else {
			json1.put("msg", supplierService.getMsg());
			json1.put("success", false);
		}
		System.out.println(PubFun.getCurrentTime());

		return json1.toString();
	}

	// 仅仅导入进货价格
	@RequestMapping(value = "/importSupMaterValueCostForOnlyCost.do", method = { RequestMethod.POST })
	@ResponseBody
	public String importSupMaterValueCostForOnlyCost(MaterVo materVo, HttpSession session) throws Exception {
		JSONObject json1 = new JSONObject();
		UserPo lgUser = (UserPo) session.getAttribute("user");
		int supId = supplierService.getSupIdByUserId(lgUser.getUserId());

		// 事物锁
		boolean lockFlag = lockTransService.lockTrans("importSupMaterValueCostForWeb.do", supId);
		if (!lockFlag) {
			json1.put("msg", "locked");
			json1.put("success", false);
			return json1.toString();
		}
		System.out.println(PubFun.getCurrentTime());
		materVo.setSupId(supId);
		boolean flag = false;
		try {
			flag = supplierService.importSupMaterValueCostForOnlyCost(materVo);

		} catch (Exception e) {
			json1.put("msg", supplierService.getMsg());
			flag = false;
		} finally {
			// 解锁
			lockTransService.unlockTrans("importSupMaterValueCostForWeb.do", supId);
		}
		if (flag) {
			json1.put("success", true);
		} else {
			json1.put("msg", supplierService.getMsg());
			json1.put("success", false);
		}
		System.out.println(PubFun.getCurrentTime());

		return json1.toString();
	}

	// 导入入库价格
	@RequestMapping(value = "/importSupMaterValueCost.do", method = { RequestMethod.POST })
	@ResponseBody
	public String importSupMaterValueCost(ExcelVo excelVo, HttpServletRequest request, HttpServletResponse response, HttpSession session)
			throws Exception {
		JSONObject json1 = new JSONObject();

		// 事物锁
		UserPo lgUser = (UserPo) session.getAttribute("user");
		int supId = supplierService.getSupIdByUserId(lgUser.getUserId());
		boolean lockFlag = lockTransService.lockTrans("importSupMaterValueCost.do", supId);
		if (!lockFlag) {
			json1.put("msg", "locked");
			json1.put("success", false);
			return json1.toString();
		}
		// 事务锁over
		try {

			MultipartFile filename = excelVo.getFilename();

			String temp = request.getSession().getServletContext().getRealPath(File.separator) + "temp"; // 临时目录
			File tempFile = new File(temp);
			if (!tempFile.exists()) {
				tempFile.mkdirs();
			}
			DiskFileUpload fu = new DiskFileUpload();
			fu.setSizeMax(10 * 1024 * 1024); // 设置允许用户上传文件大小,单位:位
			fu.setSizeThreshold(4096); // 设置最多只允许在内存中存储的数据,单位:位
			fu.setRepositoryPath(temp); // 设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录
			// 开始读取上传信息
			// int index = 0;
			if (filename == null)
				return null;

			String name = filename.getOriginalFilename();// 获取上传文件名,包括路径
			// name = name.substring(name.lastIndexOf("\\") + 1);// 从全路径中提取文件名
			long size = filename.getSize();
			if ((name == null || name.equals("")) && size == 0) {
				json1.put("msg", "msg001");
				json1.put("success", false);
				return json1.toString();
			}
			InputStream in = filename.getInputStream();

			ExcelReader excelReader = new ExcelReader();
			String[] title = excelReader.readExcelTitle(in);
			// System.out.println("获得Excel表格的标题:");
			for (String s : title) {
				System.out.print(s + " ");
			}

			// 对读取Excel表格内容测试
			Map<Integer, String> map = excelReader.readExcelContent(in, "*");

			boolean flag = false;
			try {
				flag = supplierService.importSupMaterValueCost(map);
				String[] everyline = map.get(1).split("\\*");
				supplierService.computeTotalValue(everyline[4], Integer.valueOf(new BigDecimal(everyline[2]).intValue()), 0);
			} catch (Exception e) {
				json1.put("msg", supplierService.getMsg());
				flag = false;
			}

			if (flag) {
				json1.put("success", true);
			} else {
				json1.put("msg", supplierService.getMsg());
				json1.put("success", false);
			}
		} catch (Exception e) {
			json1.put("msg", "exception");
			json1.put("success", false);
			return json1.toString();
		} finally {
			// 解锁
			lockTransService.unlockTrans("importSupMaterValueCost.do", supId);
		}
		return json1.toString();

	}

	// 自动计算行高
	public static float getExcelCellAutoHeight(String str, float fontCountInline) {
		float defaultRowHeight = 15.00f;// 每一行的高度指定
		float defaultCount = 0.00f;
		for (int i = 0; i < str.length(); i++) {
			float ff = getregex(str.substring(i, i + 1));
			defaultCount = defaultCount + ff;
		}
		return ((int) (defaultCount / fontCountInline) + 1) * defaultRowHeight;// 计算
	}

	public static float getregex(String charStr) {

		if (charStr == " ") {
			return 0.5f;
		}
		// 判断是否为字母或字符
		if (Pattern.compile("^[A-Za-z0-9]+$").matcher(charStr).matches()) {
			return 0.5f;
		}
		// 判断是否为全角

		if (Pattern.compile("[\u4e00-\u9fa5]+$").matcher(charStr).matches()) {
			return 1.00f;
		}
		// 全角符号 及中文
		if (Pattern.compile("[^x00-xff]").matcher(charStr).matches()) {
			return 1.00f;
		}
		return 0.5f;

	}

	/**
	 * 
	 * @Title: processFileName
	 * 
	 * @Description: ie,chrom,firfox下处理文件名显示乱码
	 */
	public static String processFileName(HttpServletRequest request, String fileNames) {
		String codedfilename = null;
		try {
			String agent = request.getHeader("USER-AGENT");
			if (null != agent && -1 != agent.indexOf("MSIE") || null != agent && -1 != agent.indexOf("Trident")) {// ie

				String name = java.net.URLEncoder.encode(fileNames, "UTF8");

				codedfilename = name;
			} else if (null != agent && -1 != agent.indexOf("Mozilla")) {// 火狐,chrome等

				codedfilename = new String(fileNames.getBytes("UTF-8"), "iso-8859-1");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return codedfilename;
	}

	@RequestMapping(value = "/findCustForOrder.do")
	@ResponseBody
	public String findCustForOrder(@RequestParam(required = false) String page, @RequestParam(required = false) String rows,
			SupplierOrderCustVo supplierOrderCustVo, HttpSession session) throws GenericException {
		JSONObject json = new JSONObject();
		log.info("----");
		if (page == null || page.equals(""))
			page = "1";
		if (rows == null || rows.equals(""))
			rows = "10";

		if (supplierOrderCustVo.getInitFlag() == 0) {
			json.put("success", false);
			json.put("total", 0);
			json.put("rows", null);
			return json.toString();
		}

		UserPo lgUser = (UserPo) session.getAttribute("user");
		int supId = supplierService.getSupIdByUserId(lgUser.getUserId());
		supplierOrderCustVo.setSupId(supId);
		PageController pageController = new PageController(Integer.parseInt(page), Integer.parseInt(rows));
		this.pageList = supplierService.findCustForOrder(pageController, supplierOrderCustVo);
		List<SupplierOrderCustVo> supplierOrderCustVoList = new ArrayList<SupplierOrderCustVo>();
		List items = pageList.getItems();
		if (items != null) {
			for (int i = 0; i < items.size(); i++) {
				Object[] item = (Object[]) items.get(i);
				SupplierOrderCustVo f = new SupplierOrderCustVo();
				f.setCustId((Integer) item[0]);
				f.setCustName((String) item[1]);

				supplierOrderCustVoList.add(f);
			}
		}
		json.put("success", true);
		json.put("total", pageList.getTotalCount());
		json.put("rows", supplierOrderCustVoList);
		log.info("----" + json.toString());
		return json.toString();
	}

	@RequestMapping(value = "/findSupDistribute.do")
	@ResponseBody
	public String findSupDistribute(@RequestParam(required = false) String page, @RequestParam(required = false) String rows,
			SupplierDistributeVo supplierDistributeVo, HttpSession session) throws GenericException {
		JSONObject json = new JSONObject();

		if (supplierDistributeVo.getDisDate() == null || supplierDistributeVo.getDisDate().equals("")) {
			json.put("success", false);
			json.put("total", 0);
			json.put("rows", null);
			return json.toString();
		}

		if (page == null || page.equals(""))
			page = "1";
		if (rows == null || rows.equals(""))
			rows = "10";
		UserPo lgUser = (UserPo) session.getAttribute("user");
		int supId = supplierService.getSupIdByUserId(lgUser.getUserId());
		supplierDistributeVo.setSupId(supId);
		PageController pageController = new PageController(Integer.parseInt(page), Integer.parseInt(rows));
		this.pageList = supplierService.findSupDistribute(pageController, supplierDistributeVo);
		List<SupplierDistributeVo> supplierDistributeVoList = new ArrayList<SupplierDistributeVo>();
		List items = pageList.getItems();
		if (items != null) {
			for (int i = 0; i < items.size(); i++) {
				Object[] item = (Object[]) items.get(i);
				SupplierDistributeVo f = new SupplierDistributeVo();
				f.setDisId(Long.valueOf(item[0].toString()));
				f.setSupId(Long.valueOf(item[1].toString()));
				f.setSupName((String) item[2]);
				f.setCustNameAll((String) item[3]);
				f.setDisDate((String) item[4]);
				supplierDistributeVoList.add(f);
			}
		}
		json.put("success", true);
		json.put("total", pageList.getTotalCount());
		json.put("rows", supplierDistributeVoList);
		log.info("----" + json.toString());
		return json.toString();
	}

	@RequestMapping(value = "/preSaveDistribute.do", method = { RequestMethod.GET })
	public ModelAndView preSaveDistribute(String disDate, HttpSession session) {
		Map map = new HashMap();
		UserPo lgUser = (UserPo) session.getAttribute("user");
		try {
			int supId = supplierService.getSupIdByUserId(lgUser.getUserId());
			map.put("supId", supId);
			map.put("disDate", disDate);
		} catch (GenericException e) {
			e.printStackTrace();
		}
		return new ModelAndView("/supplier/distribute/addSupperDistribute", map);
	}

	@RequestMapping(value = "/saveSupplierDistribute.do", method = { RequestMethod.POST })
	@ResponseBody
	public String saveSupplierDistribute(SupplierDistributeVo c, HttpSession session) {
		JSONObject json = new JSONObject();
		UserPo lgUser = (UserPo) session.getAttribute("user");
		try {
			boolean flag = supplierService.addSupplierDistribute(c);
			if (flag) {
				json.put("success", true);
			} else {
				json.put("success", false);
				json.put("msg", supplierService.getMsg());
			}
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
		}
		return json.toString();
	}

	@RequestMapping(value = "/deleteSupplierDistribute.do", method = { RequestMethod.POST })
	@ResponseBody
	public String deleteSupplierDistribute(long disId, HttpSession session, String disDate) {
		JSONObject json = new JSONObject();
		try {
			UserPo lgUser = (UserPo) session.getAttribute("user");
			int supId = supplierService.getSupIdByUserId(lgUser.getUserId());
			supplierService.deleteSupplierDistribute(disId, supId, disDate);
			json.put("success", true);
		} catch (Exception e) {
			json.put("success", false);
		}
		return json.toString();
	}

	@RequestMapping(value = "/preSupplierQualification.do", method = { RequestMethod.GET })
	public ModelAndView preSupplierQualification(String supplierId) {
		JSONObject json = new JSONObject();
		Map map = new HashMap();
		map.put("supplierId", supplierId);
		return new ModelAndView("/supplier/qualification/supplierQualificationIndex", map);
	}

	@RequestMapping(value = "/findSupplierQualification.do", method = { RequestMethod.POST })
	@ResponseBody
	public String findSupplierQualification(@RequestParam(required = false) String page, @RequestParam(required = false) String rows,
			SupplierQualificationVo supplierQualificationVo) throws GenericException {
		JSONObject json = new JSONObject();
		if (page == null || page.equals(""))
			page = "1";
		if (rows == null || rows.equals(""))
			rows = "10";
		PageController pageController = new PageController(Integer.parseInt(page), Integer.parseInt(rows));
		this.pageList = supplierService.findSupplierQualification(pageController, supplierQualificationVo);
		List<SupplierQualificationVo> supplierQualificationVoList = new ArrayList<SupplierQualificationVo>();
		List items = pageList.getItems();
		if (items != null) {
			for (int i = 0; i < items.size(); i++) {
				Object[] item = (Object[]) items.get(i);
				SupplierQualificationVo f = new SupplierQualificationVo();
				f.setQid((Integer) item[0]);
				f.setName((String) item[1]);
				f.setValidityDates((String) item[2]);
				f.setSupId((Integer) item[3]);
				f.setSupName((String) item[4]);
				f.setButton("下载文件");
				supplierQualificationVoList.add(f);
			}
		}
		json.put("success", true);
		json.put("total", pageList.getTotalCount());
		json.put("rows", supplierQualificationVoList);
		return json.toString();
	}

	@RequestMapping(value = "/preAddSupplierQualification.do", method = { RequestMethod.GET })
	public ModelAndView preAddSupplierQualification(int supId) {

		Map map = new HashMap();
		map.put("supId", supId);
		return new ModelAndView("/supplier/qualification/addSupperQualification", map);
	}

	@RequestMapping(value = "/saveSupplierQualification.do", method = { RequestMethod.POST })
	@ResponseBody
	public String saveSupplierQualification(SupplierQualificationVo supplierQualificationVo, HttpServletRequest request,
			HttpServletResponse response, HttpSession session) throws Exception {

		JSONObject json1 = new JSONObject();
		MultipartFile file = supplierQualificationVo.getFile();
		String temp = session.getServletContext().getRealPath(File.separator) + "temp"; // 临时目录
		File tempFile = new File(temp);
		if (!tempFile.exists()) {
			tempFile.mkdirs();
		}

		// 开始读取上传信息
		// int index = 0;
		if (file == null)
			return null;
		if (file.getSize() > 10000000) {
			throw new Exception("上传失败：文件大小不能超过10M");
		}
		String filename1 = file.getOriginalFilename();
		supplierQualificationVo.setName(filename1);
		boolean flag = supplierService.checkSupplierQualificationName(supplierQualificationVo);
		if (flag) {
			json1.put("msg", supplierService.getMsg());
			json1.put("success", false);
			return json1.toString();
		}
		log.info("----zzy2");

		if (file.getSize() > 0) {
			try {
				FileUtill.saveFileFromInputStream(file.getInputStream(), "/home/supplierQualification", filename1);
			} catch (IOException e) {
				System.out.println(e.getMessage());
				return null;
			}
		} else {
			throw new Exception("上传失败：上传文件不能为空");
		}
		// log.info("----zzy3" + "/home/context/" + filename1);

		// well, let's do nothing with the bean for now and return:
		supplierQualificationVo.setName(filename1);
		supplierService.addSupplierQualificationPo(supplierQualificationVo);
		log.info("----zzy34");

		json1.put("success", true);
		return json1.toString();
	}

	// 下载资质
	@RequestMapping(value = "/downSupplierQualification.do", method = { RequestMethod.POST })
	public void downSupplierQualification(HttpServletRequest request, HttpServletResponse response, int qid) {

		OutputStream toClient = null;

		try {
			String name = supplierService.getSupplierQualificationPoByQid(qid).getName();
			String link = "/home/supplierQualification/" + name;
			// path是指欲下载的文件的路径。
			File file = new File(link);
			// 取得文件名。
			String filename = file.getName();
			// 取得文件的后缀名。
			String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();

			// 以流的形式下载文件。
			InputStream fis = new BufferedInputStream(new FileInputStream(link));
			byte[] buffer = new byte[fis.available()];
			fis.read(buffer);
			fis.close();
			// 清空response
			response.reset();
			// 设置response的Header
			// response.addHeader("Content-Disposition", "attachment;filename="
			// + new String(filename.getBytes()));

			response.setContentType("octets/stream");
			response.addHeader("Content-Type", "text/html; charset=utf-8");
			String downLoadName = new String(filename.getBytes("gbk"), "iso8859-1");
			response.addHeader("Content-Disposition", "attachment;filename=" + downLoadName);
			// response.addHeader("Content-Disposition", "attachment;filename="
			// + filename);
			toClient = new BufferedOutputStream(response.getOutputStream());
			toClient.write(buffer);

		} catch (UnsupportedEncodingException e1) {
		} catch (Exception e) {
		} finally {
			try {
				toClient.flush();
				toClient.close();
			} catch (IOException e) {
			}
		}
	}

	// 删除资质文件
	@RequestMapping(value = "/deleteSupplierQualification.do", method = { RequestMethod.POST })
	@ResponseBody
	public String deleteSupplierQualification(int qid) {
		JSONObject json = new JSONObject();
		try {
			boolean flag = supplierService.deleteSupplierQualification(qid);
			if (flag) {
				json.put("success", true);
			} else {
				json.put("msg", supplierService.getMsg());
				json.put("success", false);
			}
		} catch (GenericException e) {
			e.printStackTrace();
		}
		return json.toString();
	}

	@RequestMapping(value = "/getSupIdByUserId.do", method = { RequestMethod.POST })
	@ResponseBody
	public String getSupIdByUserId(HttpSession session) {
		JSONObject json = new JSONObject();
		UserPo lgUser = (UserPo) session.getAttribute("user");
		try {
			long supId = supplierService.getSupIdByUserId(lgUser.getUserId());
			json.put("supId", supId);
			json.put("success", true);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
		}
		return json.toString();
	}

	@RequestMapping(value = "/getSupNameByUserId.do", method = { RequestMethod.POST })
	@ResponseBody
	public String getSupNameByUserId(HttpSession session) {
		JSONObject json = new JSONObject();
		UserPo lgUser = (UserPo) session.getAttribute("user");
		try {
			String supName = supplierService.getSupNameByUserId(lgUser.getUserId());
			json.put("supName", supName);
			json.put("success", true);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
		}
		return json.toString();
	}

	@RequestMapping(value = "/getSupPoByUserId.do", method = { RequestMethod.POST })
	@ResponseBody
	public String getSupPoByUserId(HttpSession session) {
		JSONObject json = new JSONObject();
		UserPo lgUser = (UserPo) session.getAttribute("user");
		try {
			SupplierPo tSupplierPo = supplierService.getSupPoByUserId(lgUser.getUserId());
			json.put("supName", tSupplierPo.getCompanyName());
			json.put("supId", tSupplierPo.getSupplierId());
			json.put("success", true);
		} catch (Exception e) {
			e.printStackTrace();
			json.put("success", false);
		}
		return json.toString();
	}

	// 导入实际送货数量
	@RequestMapping(value = "/importSupMaterRealityWeight.do", method = { RequestMethod.POST })
	@ResponseBody
	public String importSupMaterRealityWeight(ExcelVo excelVo, HttpServletRequest request, HttpServletResponse response, HttpSession session)
			throws Exception {
		JSONObject json1 = new JSONObject();

		// 事物锁
		UserPo lgUser = (UserPo) session.getAttribute("user");
		int supId = supplierService.getSupIdByUserId(lgUser.getUserId());
		boolean lockFlag = lockTransService.lockTrans("importSupMaterRealityWeight.do", supId);
		if (!lockFlag) {
			json1.put("msg", "locked");
			json1.put("success", false);
			return json1.toString();
		}
		// 事务锁over
		try {

			MultipartFile filename = excelVo.getFilename();

			String temp = request.getSession().getServletContext().getRealPath(File.separator) + "temp"; // 临时目录
			File tempFile = new File(temp);
			if (!tempFile.exists()) {
				tempFile.mkdirs();
			}
			DiskFileUpload fu = new DiskFileUpload();
			fu.setSizeMax(10 * 1024 * 1024); // 设置允许用户上传文件大小,单位:位
			fu.setSizeThreshold(4096); // 设置最多只允许在内存中存储的数据,单位:位
			fu.setRepositoryPath(temp); // 设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录
			// 开始读取上传信息
			// int index = 0;
			if (filename == null)
				return null;

			String name = filename.getOriginalFilename();// 获取上传文件名,包括路径
			// name = name.substring(name.lastIndexOf("\\") + 1);// 从全路径中提取文件名
			long size = filename.getSize();
			if ((name == null || name.equals("")) && size == 0) {
				json1.put("msg", "msg001");
				json1.put("success", false);
				return json1.toString();
			}
			InputStream in = filename.getInputStream();

			ExcelReader excelReader = new ExcelReader();
			/*
			 * String[] title = excelReader.readExcelTitle(in); //
			 * System.out.println("获得Excel表格的标题:"); for (String s : title) {
			 * System.out.print(s + " "); }
			 */

			// 根据总表取出时间
			Map<Integer, String> map = excelReader.readExcelContent(in, "*");
			String materday = map.get(1).split("\\*")[4];

			// 对读取Excel表格内容测试
			List<Map<Integer, String>> list = excelReader.readExcelContentAllSheet(in);

			boolean flag = false;
			try {
				flag = supplierService.importSupMaterRealityWeight(list, materday, supId);
				String[] everyline = map.get(1).split("\\*");
				supplierService.computeTotalValue(everyline[4], Integer.valueOf(new BigDecimal(everyline[2]).intValue()), 0);
			} catch (Exception e) {
				json1.put("msg", supplierService.getMsg());
				flag = false;
			}

			if (flag) {
				json1.put("success", true);
			} else {
				json1.put("msg", supplierService.getMsg());
				json1.put("success", false);
			}
		} catch (Exception e) {
			json1.put("msg", "exception");
			json1.put("success", false);
			return json1.toString();
		} finally {
			// 解锁
			lockTransService.unlockTrans("importSupMaterRealityWeight.do", supId);
		}
		return json1.toString();

	}

	@RequestMapping(value = "/listSupplierCost.do", method = { RequestMethod.POST })
	@ResponseBody
	public String listSupplierCost(@RequestParam(required = false) String page, @RequestParam(required = false) String rows,
			MaterVoForCostSupplier materVo, HttpSession session) throws GenericException {
		JSONObject json = new JSONObject();
		if (page == null || page.equals(""))
			page = "1";
		if (rows == null || rows.equals(""))
			rows = "1000";
		List<MaterVoForCostSupplier> materList = new ArrayList<MaterVoForCostSupplier>();
		UserPo userInfo = (UserPo) session.getAttribute("user");
		long supId = supplierService.getSupIdByUserId(userInfo.getUserId());
		materVo.setSupId((int) supId);
		if (materVo.getInitFlag() == 0) {
			json.put("success", false);
			json.put("total", 0);
			json.put("rows", materList);
			return json.toString();
		}
		PageController pageController = new PageController(Integer.parseInt(page), Integer.parseInt(rows));
		this.pageList = supplierService.listSupplierCost(pageController, materVo);

		List items = pageList.getItems();
		if (items != null) {
			for (int i = 0; i < items.size(); i++) {
				Object[] item = (Object[]) items.get(i);
				MaterVoForCostSupplier f = new MaterVoForCostSupplier();
				f.setMaterId((Integer) item[0]);
				f.setMaterLevel((Integer) item[1]);
				f.setMaterName((String) item[4]);
				f.setSpecifications((String) item[9]);
				f.setBrands((String) item[8]);
				f.setMaterTypeName((String) item[6]);
				f.setMaterWeight(item[3].toString());
				f.setUnit((String) item[7]);
				f.setContent("检索最后一次报价");
				if (item[10] != null && !item[10].toString().equals("0")) {
					f.setMaterValue(new BigDecimal(item[10].toString()));
					f.setSubmitCostFlag(1);
				} else {
					f.setSubmitCostFlag(0);
				}
				materList.add(f);

			}
		}
		json.put("success", true);
		json.put("total", pageList.getTotalCount());
		json.put("rows", materList);
		return json.toString();
	}

	@RequestMapping(value = "/webSupplierInValueJsonForState.do", method = { RequestMethod.GET })
	@ResponseBody
	public String webSupplierInValueJsonForState(String date, HttpSession session) throws GenericException {
		JSONObject json = new JSONObject();

		// return json.toString();
		return "[{\"title\": \"All Day Event\",\"start\": \"2016-08-01\"}]";
	}

	@RequestMapping(value = "/listSupplier.do", method = { RequestMethod.POST })
	@ResponseBody
	public String listSupplier(@RequestParam(required = false) String page, @RequestParam(required = false) String rows, MaterVo materVo,
			HttpSession session) throws GenericException {
		JSONObject json = new JSONObject();
		if (page == null || page.equals(""))
			page = "1";
		if (rows == null || rows.equals(""))
			rows = "1000";
		List<MaterVo> materList = new ArrayList<MaterVo>();
		UserPo userInfo = (UserPo) session.getAttribute("user");
		long supId = supplierService.getSupIdByUserId(userInfo.getUserId());
		materVo.setSupId((int) supId);
		if (materVo.getInitFlag() == 0) {
			json.put("success", false);
			json.put("total", 0);
			json.put("rows", materList);
			return json.toString();
		}
		PageController pageController = new PageController(Integer.parseInt(page), Integer.parseInt(rows));
		this.pageList = supplierService.listSupplier(pageController, materVo);

		List items = pageList.getItems();
		if (items != null) {
			for (int i = 0; i < items.size(); i++) {
				Object[] item = (Object[]) items.get(i);
				MaterVo f = new MaterVo();
				f.setMaterId((Integer) item[0]);
				f.setMaterLevel((Integer) item[1]);
				f.setMaterWeight(item[3].toString());
				f.setMaterWeightNeed(item[10].toString());
				f.setMaterName((String) item[4]);
				f.setUnit((String) item[5]);
				f.setSpecifications((String) item[6]);
				f.setBrands((String) item[11]);
				f.setMaterTypeName((String) item[9]);
				if (item[7] != null) {
					f.setMaterValue(new BigDecimal(item[7].toString()));
				} else {
					f.setMaterValue(new BigDecimal(0));
				}
				if (item[8] != null) {
					f.setMaterValueAll(new BigDecimal(item[8].toString()));
				} else {
					f.setMaterValueAll(new BigDecimal(0));
				}
				f.setOrdId(Integer.valueOf(item[12].toString()));
				materList.add(f);
			}
		}
		json.put("success", true);
		json.put("total", pageList.getTotalCount());
		json.put("rows", materList);
		return json.toString();
	}

	@RequestMapping(value = "/findSupType.do", method = { RequestMethod.POST })
	@ResponseBody
	public String shopForSupplier(HttpServletRequest request, HttpServletResponse response, long supId) {
		JSONObject json = new JSONObject();
		json.put("success", true);
		String userTestValue = "";
		try {
			userTestValue = userService.getSupType(supId);
		} catch (GenericException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		json.put("materType", userTestValue);
		return json.toString();
	}

	// 检索最后一次提交价格
	@RequestMapping(value = "/getMaterValueCostByMaterId.do", method = { RequestMethod.POST })
	@ResponseBody
	public String getMaterValueCostByMaterId(HttpSession session, HttpServletRequest request, HttpServletResponse response, int materId) {
		JSONObject json = new JSONObject();
		json.put("success", true);
		BigDecimal materValueCost = new BigDecimal(0);

		UserPo userInfo = (UserPo) session.getAttribute("user");
		BigDecimal materValueReal = new BigDecimal(0);
		try {
			int supId = supplierService.getSupIdByUserId(userInfo.getUserId());
			materValueCost = supplierService.getMaterValueCostByMaterId(materId, supId);
		} catch (GenericException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		json.put("materValueCost", materValueCost);
		return json.toString();
	}

	@RequestMapping(value = "/getMaterValueCostByMaterIdForBatch.do", method = { RequestMethod.POST })
	@ResponseBody
	public String getMaterValueCostByMaterIdForBatch(HttpSession session, HttpServletRequest request, HttpServletResponse response, String materJson) {
		JSONObject json = new JSONObject();
		json.put("success", true);
		BigDecimal materValueCost = new BigDecimal(0);

		/*
		 * UserPo userInfo = (UserPo) session.getAttribute("user"); BigDecimal
		 * materValueReal = new BigDecimal(0); try { int supId =
		 * supplierService.getSupIdByUserId(userInfo.getUserId());
		 * materValueCost = supplierService.getMaterValueCostByMaterId(materId,
		 * supId); } catch (GenericException e) { // TODO Auto-generated catch
		 * block e.printStackTrace(); }
		 */
		json.put("materValueCost", materValueCost);
		return json.toString();
	}

	@RequestMapping(value = "/getMaterValueRealByMaterId.do", method = { RequestMethod.POST })
	@ResponseBody
	public String getMaterValueRealByMaterId(HttpSession session, HttpServletResponse response, int materId, BigDecimal materValueCost, long shopId) {
		JSONObject json = new JSONObject();
		json.put("success", true);

		UserPo userInfo = (UserPo) session.getAttribute("user");
		BigDecimal materValueReal = new BigDecimal(0);
		try {
			int supId = supplierService.getSupIdByUserId(userInfo.getUserId());
			materValueReal = supplierService.getMaterValueRealByMaterId(materId, materValueCost, supId, shopId);
		} catch (GenericException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		json.put("materValueReal", materValueReal);
		return json.toString();
	}

	// 供货商商店选择
	@RequestMapping(value = "/getAllSup.do", method = { RequestMethod.POST })
	public void getAllSup(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
		JSONObject json = new JSONObject();
		json.put("success", true);
		response.setContentType("text/json;charset=UTF-8");
		PrintWriter writer;
		try {
			String userTestValue = supplierService.getAllSup();
			writer = response.getWriter();
			writer.write(userTestValue);
			writer.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (GenericException e) {
			e.printStackTrace();
		}
		// return json.toString();
	}

	// 供货商商店选择
	@RequestMapping(value = "/getSupByMaterType.do", method = { RequestMethod.POST })
	public void getSupByMaterType(HttpServletRequest request, HttpServletResponse response, HttpSession session, int supMaterType) {
		JSONObject json = new JSONObject();
		json.put("success", true);
		response.setContentType("text/json;charset=UTF-8");
		PrintWriter writer;
		try {
			String userTestValue = supplierService.getSupByMaterType(supMaterType);
			writer = response.getWriter();
			writer.write(userTestValue);
			writer.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (GenericException e) {
			e.printStackTrace();
		}
		// return json.toString();
	}

	// 导入价格和数量
	@RequestMapping(value = "/importSupMaterRealityWeightForWeb.do", method = { RequestMethod.POST })
	@ResponseBody
	public String importSupMaterRealityWeightForWeb(MaterVo materVo, HttpServletRequest request, HttpServletResponse response, HttpSession session)
			throws Exception {
		JSONObject json1 = new JSONObject();
		UserPo lgUser = (UserPo) session.getAttribute("user");
		int supId = supplierService.getSupIdByUserId(lgUser.getUserId());

		// 事物锁
		boolean lockFlag = lockTransService.lockTrans("importSupMaterRealityWeightForWeb.do", supId);
		if (!lockFlag) {
			json1.put("msg", "locked");
			json1.put("success", false);
			return json1.toString();
		}

		materVo.setSupId(supId);
		boolean flag = false;
		try {
			flag = supplierService.importSupMaterRealityWeightForWeb(materVo);
			supplierService.computeTotalValue(materVo.getDate(), materVo.getSupId(), materVo.getOrdId());

			// supplierService.computeTotalValue(materVo.getDate(),
			// materVo.getSupId());
		} catch (Exception e) {
			json1.put("msg", supplierService.getMsg());
			flag = false;
		} finally {
			// 解锁
			lockTransService.unlockTrans("importSupMaterRealityWeightForWeb.do", supId);
		}
		if (flag) {
			json1.put("success", true);
		} else {
			json1.put("msg", supplierService.getMsg());
			json1.put("success", false);
		}
		return json1.toString();
	}

	// 导入价格和数量
	@RequestMapping(value = "/importSupMaterWeightForWeb.do", method = { RequestMethod.POST })
	@ResponseBody
	public String importSupMaterWeightForWeb(MaterVo materVo, HttpServletRequest request, HttpServletResponse response, HttpSession session)
			throws Exception {
		JSONObject json1 = new JSONObject();
		UserPo lgUser = (UserPo) session.getAttribute("user");
		int supId = supplierService.getSupIdByUserId(lgUser.getUserId());

		// 事物锁
		boolean lockFlag = lockTransService.lockTrans("importSupMaterWeightForWeb.do", supId);
		if (!lockFlag) {
			json1.put("msg", "locked");
			json1.put("success", false);
			return json1.toString();
		}

		materVo.setSupId(supId);
		boolean flag = false;
		try {
			flag = supplierService.importSupMaterWeightForWeb(materVo);
			// supplierService.computeTotalValue(materVo.getDate(),
			// materVo.getSupId(), materVo.getOrdId());

			// supplierService.computeTotalValue(materVo.getDate(),
			// materVo.getSupId());
		} catch (Exception e) {
			json1.put("msg", supplierService.getMsg());
			flag = false;
		} finally {
			// 解锁
			lockTransService.unlockTrans("importSupMaterWeightForWeb.do", supId);
		}
		if (flag) {
			json1.put("success", true);
		} else {
			json1.put("msg", supplierService.getMsg());
			json1.put("success", false);
		}
		return json1.toString();
	}

	// 批量改变材料数量
	@RequestMapping(value = "/updateSupMaterWeightForBatch.do", method = { RequestMethod.POST })
	@ResponseBody
	public String updateSupMaterWeightForBatch(MaterVo materVo, HttpServletRequest request, HttpServletResponse response, HttpSession session)
			throws Exception {
		JSONObject json1 = new JSONObject();
		UserPo lgUser = (UserPo) session.getAttribute("user");
		int supId = supplierService.getSupIdByUserId(lgUser.getUserId());

		// 事物锁
		boolean lockFlag = lockTransService.lockTrans("updateSupMaterWeightForBatch.do", supId);
		if (!lockFlag) {
			json1.put("msg", "locked");
			json1.put("success", false);
			return json1.toString();
		}

		materVo.setSupId(supId);
		boolean flag = false;
		try {
			flag = supplierService.updateSupMaterWeightForBatch(materVo);

		} catch (Exception e) {
			json1.put("msg", supplierService.getMsg());
			flag = false;
		} finally {
			// 解锁
			lockTransService.unlockTrans("updateSupMaterWeightForBatch.do", supId);
		}
		if (flag) {
			json1.put("success", true);
		} else {
			json1.put("msg", supplierService.getMsg());
			json1.put("success", false);
		}
		return json1.toString();
	}

	@RequestMapping(value = "/getUserForSupplierCompany.do", method = { RequestMethod.POST })
	@ResponseBody
	public String getUserForSupplierCompany(SupplierVo userVo, HttpServletRequest request, HttpServletResponse response) {
		String userLevel = "";
		try {
			response.setContentType("text/html;charset=UTF-8");
			userLevel = userService.getUserForSupplierCompany(userVo);

		} catch (GenericException e) {
			e.printStackTrace();
		}

		return userLevel;
	}

}
